:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border-color: #30363d;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --success: #3fb950;
    --error: #f85149;
    --warning: #d29922;
    --sidebar-width: 260px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.2s;
}

#sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

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

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

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

.conversation-item {
    padding: 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.1s;
}

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

.conversation-item.active {
    background: var(--accent);
    color: white;
}

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

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

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

/* Header */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    gap: 16px;
}

#header-left, #header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

#header h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

#connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

#status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error);
}

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

/* Working directory bar */
#workdir-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

#workdir-bar label {
    color: var(--text-secondary);
    white-space: nowrap;
}

#workdir-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

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

/* Messages */
#messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

#messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 900px;
    margin: 0 auto;
}

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

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

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

.message.assistant .content {
    white-space: pre-wrap;
    word-break: break-word;
}

.message.tool-use, .message.tool-result {
    align-self: flex-start;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    font-size: 13px;
    max-width: 100%;
}

.message.tool-use .tool-header,
.message.tool-result .result-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-weight: 500;
}

.message.tool-use .tool-header { color: var(--warning); }
.message.tool-result .result-header.success { color: var(--success); }
.message.tool-result .result-header.error { color: var(--error); }

.message.tool-use .tool-input,
.message.tool-result .result-content {
    background: var(--bg-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
}

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

.streaming-indicator {
    display: inline-block;
    width: 8px;
    height: 16px;
    background: var(--accent);
    animation: blink 1s infinite;
    margin-left: 2px;
    vertical-align: text-bottom;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Input area */
#input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

#input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    max-width: 900px;
    margin: 0 auto;
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    max-height: 200px;
    line-height: 1.5;
}

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

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

#input-actions {
    display: flex;
    gap: 8px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn:hover:not(:disabled) {
    opacity: 0.9;
}

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

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

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

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

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

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, color 0.1s;
}

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

/* Select */
.select {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
}

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

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    max-width: 400px;
    width: 90%;
}

.modal-content.wide {
    max-width: 600px;
}

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

.modal-header h2 {
    margin: 0;
    font-size: 18px;
}

.modal-body {
    margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.modal-content h2 {
    margin: 0 0 8px 0;
    font-size: 18px;
}

.modal-content p {
    margin: 0 0 16px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.modal-content input[type="password"],
.modal-content input[type="text"] {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 16px;
}

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

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

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

.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    resize: vertical;
}

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

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.form-group input[readonly] {
    background: var(--bg-tertiary);
    cursor: default;
}

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

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

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

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

/* Responsive */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
    }

    #sidebar.collapsed {
        margin-left: calc(-1 * var(--sidebar-width));
    }
}
