/* Status dot pulse animation for connecting state */
@keyframes status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
.status-connecting {
    animation: status-pulse 1.2s ease-in-out infinite;
}

/* Chat bubble styling */
.msg-user {
    display: flex;
    justify-content: flex-end;
}
.msg-assistant {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.bubble {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    line-height: 1.5;
    word-break: break-word;
}
.bubble-user {
    background-color: #2563eb;
    color: white;
    border-bottom-right-radius: 0.25rem;
    white-space: pre-wrap;
}
.bubble-assistant {
    background-color: #f3f4f6;
    color: #1f2937;
    border-bottom-left-radius: 0.25rem;
}

/* Markdown content inside assistant bubbles */
.bubble-assistant p { margin: 0.5em 0; }
.bubble-assistant p:first-child { margin-top: 0; }
.bubble-assistant p:last-child { margin-bottom: 0; }
.bubble-assistant pre {
    background: #1f2937;
    color: #e5e7eb;
    border-radius: 0.5rem;
    padding: 0.75rem;
    overflow-x: auto;
    margin: 0.5em 0;
    font-size: 0.875rem;
}
.bubble-assistant code {
    font-family: ui-monospace, monospace;
    font-size: 0.875em;
}
.bubble-assistant :not(pre) > code {
    background: #e5e7eb;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
}
.bubble-assistant ul, .bubble-assistant ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}
.bubble-assistant li { margin: 0.25em 0; }
.bubble-assistant a { color: #2563eb; text-decoration: underline; }
.bubble-assistant table {
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 0.875rem;
}
.bubble-assistant th, .bubble-assistant td {
    border: 1px solid #d1d5db;
    padding: 0.375rem 0.5rem;
}

/* Message entrance animation */
.msg-enter {
    animation: msgSlideIn 0.2s ease-out;
}
@keyframes msgSlideIn {
    from { opacity: 0; transform: translateY(0.5rem); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Loading dots */
.loading-dots span {
    animation: blink 1.4s infinite both;
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    background: #9ca3af;
    border-radius: 50%;
    margin: 0 0.125rem;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* Agent badge on assistant messages */
.agent-badge {
    display: inline-block;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6b7280;
    background: #e5e7eb;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    margin-bottom: 0.25rem;
    align-self: flex-start;
}
.model-badge {
    display: inline-block;
    font-size: 0.5625rem;
    font-weight: 500;
    color: #9ca3af;
    margin-left: 0.25rem;
    margin-bottom: 0.25rem;
    align-self: flex-start;
}

/* Thinking blocks (intermediate Claude text before tool calls) */
.thinking-block {
    display: flex;
    align-items: flex-start;
}
.thinking-content {
    font-size: 0.8rem;
    font-style: italic;
    color: #9ca3af;
    line-height: 1.4;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

/* Tool status blocks */
.tool-status-line {
    color: #9ca3af;
    overflow-wrap: anywhere;
}

/* Tool parameter details */
.tool-params {
    margin-left: 1.25rem;
    margin-top: 0.125rem;
    font-family: ui-monospace, monospace;
    font-size: 0.75rem;
    color: #6b7280;
    overflow-wrap: anywhere;
    line-height: 1.4;
}

/* Sidebar responsive */
.sidebar-backdrop {
    display: none;
}
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -16rem;
        top: 0;
        bottom: 0;
        z-index: 50;
        transition: left 0.2s ease;
    }
    .sidebar-open {
        left: 0;
    }
    .sidebar-open ~ .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 40;
    }
}

/* ---- Tab bar ---- */
.tab-btn {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    background: none;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover {
    color: #374151;
}
.tab-btn.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
}
.tab-content.hidden {
    display: none;
}

/* Settings sections */
.settings-section {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 1.5rem;
}

/* Theme toggle buttons */
.theme-toggle-btn {
    border-color: #d1d5db;
    color: #374151;
    background: white;
}
.theme-toggle-btn.selected {
    border-color: #2563eb;
    background: #eff6ff;
    color: #2563eb;
    font-weight: 600;
}

/* ---- Dark theme ---- */
[data-theme="dark"] body {
    background-color: #111827;
    color: #e5e7eb;
}

[data-theme="dark"] .dark-bg,
[data-theme="dark"] .settings-section {
    background-color: #1f2937;
}

[data-theme="dark"] .dark-border,
[data-theme="dark"] .settings-section {
    border-color: #374151;
}

[data-theme="dark"] .dark-text {
    color: #e5e7eb;
}

[data-theme="dark"] .dark-label {
    color: #9ca3af;
}

[data-theme="dark"] .dark-input {
    background-color: #1f2937;
    color: #e5e7eb;
    border-color: #4b5563;
}

[data-theme="dark"] .dark-btn {
    background-color: #374151;
}
[data-theme="dark"] .dark-btn:hover {
    background-color: #4b5563;
}

/* Dark theme - chat area */
[data-theme="dark"] #messages {
    background-color: #111827;
}

[data-theme="dark"] .bubble-assistant {
    background-color: #1f2937;
    color: #e5e7eb;
}
[data-theme="dark"] .bubble-assistant :not(pre) > code {
    background: #374151;
    color: #e5e7eb;
}

[data-theme="dark"] .agent-badge {
    background: #374151;
    color: #9ca3af;
}
[data-theme="dark"] .model-badge {
    color: #6b7280;
}

/* Dark theme - tab bar */
[data-theme="dark"] .tab-btn {
    color: #9ca3af;
}
[data-theme="dark"] .tab-btn:hover {
    color: #e5e7eb;
}
[data-theme="dark"] .tab-btn.active {
    color: #60a5fa;
    border-bottom-color: #60a5fa;
}

/* Dark theme - settings/analytics tab background */
[data-theme="dark"] #tab-settings,
[data-theme="dark"] #tab-analytics {
    background-color: #111827;
}

/* Dark theme - theme toggle buttons */
[data-theme="dark"] .theme-toggle-btn {
    border-color: #4b5563;
    color: #e5e7eb;
    background: #1f2937;
}
[data-theme="dark"] .theme-toggle-btn.selected {
    border-color: #60a5fa;
    background: #1e3a5f;
    color: #60a5fa;
}

/* Dark theme - thinking blocks & tool status */
[data-theme="dark"] .thinking-content {
    color: #9ca3af;
}
[data-theme="dark"] .tool-status-line {
    color: #6b7280;
}
[data-theme="dark"] .tool-params {
    color: #9ca3af;
}

/* ---- Attachment preview (below input) ---- */
.attachment-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 0;
}
.attachment-preview.hidden { display: none; }

.attachment-thumb {
    position: relative;
    width: 4rem;
    height: 4rem;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid #d1d5db;
}
.attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.attachment-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    color: #374151;
    background: #f9fafb;
    max-width: 10rem;
}
.attachment-badge .badge-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.attachment-remove {
    position: absolute;
    top: -0.25rem;
    right: -0.25rem;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: #ef4444;
    color: white;
    border: none;
    font-size: 0.7rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.attachment-badge-wrap {
    position: relative;
}
.attachment-badge-wrap .attachment-remove {
    top: -0.25rem;
    right: -0.25rem;
}

/* Attachments rendered in user messages */
.user-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 0.375rem;
    justify-content: flex-end;
}
.chat-thumbnail {
    max-width: 12rem;
    max-height: 10rem;
    border-radius: 0.5rem;
    cursor: pointer;
}
.chat-thumbnail:hover { opacity: 0.9; }
.file-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: rgba(255,255,255,0.2);
    border-radius: 0.375rem;
    font-size: 0.75rem;
}

/* Drop zone highlight */
#input-area.drop-active {
    outline: 2px dashed #3b82f6;
    outline-offset: 2px;
    border-radius: 0.5rem;
}

/* ---- Dark theme - attachments ---- */
[data-theme="dark"] .attachment-thumb {
    border-color: #4b5563;
}
[data-theme="dark"] .attachment-badge {
    border-color: #4b5563;
    color: #e5e7eb;
    background: #374151;
}
[data-theme="dark"] .file-badge {
    background: rgba(255,255,255,0.15);
}

/* ---- Diff proposal cards ---- */
.diff-proposal {
    background: var(--diff-bg, #1e293b);
    border: 1px solid var(--diff-border, #334155);
    border-radius: 8px;
    overflow: hidden;
    margin: 4px 0;
    max-width: 100%;
}
.diff-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--diff-border, #334155);
    font-size: 13px;
    font-weight: 600;
}
.diff-title { color: #e2e8f0; }
.diff-file { border-bottom: 1px solid var(--diff-border, #334155); }
.diff-file:last-of-type { border-bottom: none; }
.diff-filename {
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    background: rgba(0,0,0,0.15);
}
.diff-content {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
}
.diff-add { background: rgba(34, 197, 94, 0.15); color: #4ade80; padding: 0 12px; white-space: pre; }
.diff-del { background: rgba(239, 68, 68, 0.15); color: #f87171; padding: 0 12px; white-space: pre; }
.diff-ctx { color: #94a3b8; padding: 0 12px; white-space: pre; }
.diff-hunk { color: #60a5fa; padding: 2px 12px; font-size: 11px; }
.diff-truncated { color: #64748b; padding: 4px 12px; font-style: italic; }
.diff-actions {
    padding: 8px 12px;
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--diff-border, #334155);
}
.diff-btn {
    padding: 4px 14px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s;
}
.diff-btn:hover { opacity: 0.85; }
.diff-btn-approve { background: #22c55e; color: white; }
.diff-btn-reject { background: #ef4444; color: white; }
.diff-btn-view { background: #3b82f6; color: white; }
.diff-status-pending { color: #fbbf24; font-size: 12px; font-weight: 600; }
.diff-status-approved { color: #4ade80; font-size: 12px; font-weight: 600; }
.diff-status-rejected { color: #f87171; font-size: 12px; font-weight: 600; }

/* Light theme overrides for diff cards */
[data-theme="light"] .diff-proposal { --diff-bg: #f8fafc; --diff-border: #e2e8f0; }
[data-theme="light"] .diff-title { color: #1e293b; }
[data-theme="light"] .diff-add { background: rgba(34, 197, 94, 0.1); color: #16a34a; }
[data-theme="light"] .diff-del { background: rgba(239, 68, 68, 0.1); color: #dc2626; }
[data-theme="light"] .diff-ctx { color: #64748b; }
[data-theme="light"] .diff-hunk { color: #2563eb; }
