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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #1a1a1a;
    color: #e0e0e0;
}

/* Sidebar */
.sidebar {
    background: #2a2a2a;
    border-right: 1px solid #3a3a3a;
    padding: 20px;
    overflow-y: auto;
}

/* Chat layout */
.chat-container {
    display: flex;
    flex-direction: column;
    padding: 20px;
    height: 100%;
    min-height: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
    min-height: 0;
}

/* Messages */
.message {
    margin-bottom: 15px;
    padding: 12px;
    border-radius: 8px;
    max-width: 80%;
}

.message.user {
    background: #0066cc;
    margin-left: auto;
    text-align: right;
}

.message.ai,
.message.assistant {
    background: #2a2a2a;
}

.message-role {
    font-weight: bold;
    margin-bottom: 5px;
    font-size: 0.9em;
    opacity: 0.8;
}

.message-content {
    line-height: 1.5;
}

/* Markdown styling */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 0.8em 0 0.5em 0;
    font-weight: bold;
}

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

.message-content p {
    margin: 0.5em 0;
}

.message-content p:first-child {
    margin-top: 0;
}

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

.message-content code {
    background: #1a1a1a;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: #1a1a1a;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.8em 0;
}

.message-content pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
}

.message-content ul,
.message-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message-content li {
    margin: 0.3em 0;
}

.message-content a {
    color: #4da6ff;
    text-decoration: none;
}

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

.message-content blockquote {
    border-left: 3px solid #0066cc;
    padding-left: 12px;
    margin: 0.8em 0;
    color: #b0b0b0;
}

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

.message-content table th,
.message-content table td {
    border: 1px solid #3a3a3a;
    padding: 8px;
    text-align: left;
}

.message-content table th {
    background: #1a1a1a;
    font-weight: bold;
}

.message-content hr {
    border: none;
    border-top: 1px solid #3a3a3a;
    margin: 1em 0;
}

.message-content strong {
    font-weight: bold;
}

.message-content em {
    font-style: italic;
}

.message-content img {
    max-width: 100%;
    height: auto;
    margin: 1rem 0;
    border-radius: 8px;
    border: 1px solid #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    display: block;
}

/* Chat input */
.chat-input {
    display: flex;
    gap: 10px;
}

.chat-input-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-input textarea {
    resize: none;
    width: 100%;
}

/* Image preview strip (above textarea) */
.image-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.image-preview-item {
    position: relative;
    display: inline-block;
}

.image-preview-item img {
    height: 64px;
    width: 64px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #555;
}

.image-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #555;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.image-preview-remove:hover {
    background: #e55;
}

/* Thumbnail strip inside user messages */
.message-image-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}

.message-image-thumb {
    height: 80px;
    width: 80px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #555;
    cursor: pointer;
}

.message-image-thumb:hover {
    opacity: 0.85;
}

/* Sidebar tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tab {
    flex: 1;
    padding: 10px;
    background: #1a1a1a;
    border: none;
    border-radius: 8px;
    color: #e0e0e0;
    cursor: pointer;
}

.tab.active {
    background: #0066cc;
}

.panel {
    display: none;
}

.panel.active {
    display: block;
}

/* Conversation list */
.conversation-item {
    background: #1a1a1a;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    position: relative;
    border: 1px solid transparent;
}

.conversation-item:hover {
    background: #222;
    border-color: #3a3a3a;
}

.conversation-item.active {
    border-color: #0066cc;
    background: #1a2a3a;
}

.conversation-title {
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 20px;
}

.conversation-meta {
    font-size: 0.75em;
    color: #666;
    margin-top: 2px;
}

.conversation-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: #666;
    font-size: 1.1em;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.conversation-delete:hover {
    color: #cc0000;
}

.conversation-rename-input {
    width: 100%;
    background: #2a2a2a;
    border: 1px solid #0066cc;
    border-radius: 4px;
    color: #e0e0e0;
    padding: 2px 6px;
    font-size: 0.9em;
    outline: none;
}

.context-messages {
    margin-top: 10px;
}

.context-item {
    background: #1a1a1a;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 0.9em;
}

.context-item strong {
    color: #0066cc;
    display: block;
    margin-bottom: 4px;
}

/* Thinking indicator */
.thinking {
    color: #888;
    font-style: italic;
}

.thinking .dots::after {
    content: '';
    animation: dots 1.5s steps(3, end) infinite;
}

@keyframes dots {
    0%   { content: ''; }
    33%  { content: '.'; }
    66%  { content: '..'; }
    100% { content: '...'; }
}

/* Context compaction */
.compaction-badge {
    display: inline-block;
    background: #2d4a2d;
    color: #7ec87e;
    font-size: 0.75em;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 6px;
    font-weight: normal;
    vertical-align: middle;
}

.context-usage {
    font-size: 0.8em;
    color: #888;
    margin: 8px 0;
}

.compact-button {
    background: #2d4a2d;
    color: #7ec87e;
    border: 1px solid #3a5a3a;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 0.8em;
    cursor: pointer;
    margin: 6px 0;
}

.compact-button:hover {
    background: #3a5a3a;
}

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

.usage-bar {
    display: inline-block;
    width: 80px;
    height: 6px;
    background: #333;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 6px;
    overflow: hidden;
}

.usage-fill {
    display: block;
    height: 100%;
    background: #4a9eff;
    border-radius: 3px;
    transition: width 0.3s;
}

/* Agent selector */
.agent-label {
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #666;
    margin-bottom: 8px;
}

.agent-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.agent-btn {
    background: #1a1a1a;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    color: #aaa;
    cursor: pointer;
    font-size: 0.78em;
    padding: 4px 10px;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.agent-btn:hover {
    background: #222;
    border-color: #555;
    color: #e0e0e0;
}

.agent-btn.active {
    background: #0a3a6e;
    border-color: #0066cc;
    color: #4da6ff;
}

/* Agent switch inline badge */
.agent-switch-badge {
    display: inline-block;
    background: #1a2d1a;
    border: 1px solid #2a4a2a;
    border-radius: 12px;
    color: #7ec87e;
    font-size: 0.78em;
    padding: 3px 10px;
    margin-bottom: 6px;
}

/* Tool call display */
.tool-calls-container {
    margin-bottom: 10px;
}

.tool-call {
    background: #1e1e2e;
    border: 1px solid #333;
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 0.85em;
}

.tool-call summary {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
    user-select: none;
}

.tool-call summary::-webkit-details-marker {
    display: none;
}

.tool-call summary::before {
    content: '\25B6';
    font-size: 0.7em;
    transition: transform 0.15s;
}

.tool-call[open] summary::before {
    transform: rotate(90deg);
}

.tool-call .tool-name {
    color: #7aa2f7;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-weight: 600;
}

.tool-call .tool-timing {
    color: #888;
    margin-left: auto;
    font-size: 0.9em;
}

.tool-call.running .tool-timing {
    color: #e0af68;
    font-style: italic;
}

.tool-call.running .tool-timing .dots::after {
    content: '';
    animation: dots 1.5s steps(3, end) infinite;
}

.tool-call.error .tool-name {
    color: #f7768e;
}

.tool-call .tool-body {
    padding: 0 12px 10px;
    border-top: 1px solid #333;
}

.tool-call .tool-input,
.tool-call .tool-output {
    margin-top: 8px;
}

.tool-call .tool-input strong,
.tool-call .tool-output strong {
    display: block;
    color: #888;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.tool-call .tool-output img {
    max-width: 100%;
    height: auto;
    margin-top: 10px;
    border-radius: 8px;
    border: 1px solid #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.tool-call pre {
    background: #151520;
    padding: 8px 10px;
    border-radius: 4px;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    color: #c0c0c0;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
}

/* Message error state */
.message.error-msg {
    background: rgba(204, 0, 0, 0.12);
    border: 1px solid #880000;
    color: #ff8080;
    font-style: italic;
}

/* Disabled submit button */
.chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Login page */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-error {
    background: rgba(204, 0, 0, 0.15);
    border: 1px solid #cc0000;
    color: #ff6666;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.9em;
}

/* Responsive: stack sidebar on mobile */
@media (max-width: 767.98px) {
    .sidebar {
        max-height: 30vh;
        border-right: none;
        border-bottom: 1px solid #3a3a3a;
    }
}
