body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    margin: 0;
    background-color: #f4f4f4;
}

.chat-container {
    width: 100vw;
    height: 100vh;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
}

.chat-box {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    border-bottom: 1px solid #eee;
}

.message {
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 80%;
    word-wrap: break-word;
}

.message p {
    margin: 0;
    line-height: 1.4;
}

.user-message {
    background-color: #0056b3;
    color: white;
    margin-left: auto;
}

.bot-message {
    background-color: #e9ecef;
    color: #333;
}

.error-message {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.warning-message {
    background-color: #fff3cd;
    color: #856404;
}

.info-message {
    font-style: italic;
    color: #5a6e81;
    font-size: 0.9em;
    text-align: center;
    max-width: 90%;
    margin-left: auto;
    margin-right: auto;
    background: none;
    padding: 5px 0;
}

/* --- Collapsible "Show agent's work" --- */
.thinking-process {
    background-color: #f4f7f9;
    border: 1px solid #e0e6ec;
    border-radius: 12px;
    padding: 8px 12px;
    margin: 8px auto;
    font-size: 0.85em;
    color: #5a6e81;
    max-width: 90%;
}
.thinking-process summary {
    cursor: pointer;
    font-weight: 500;
    outline: none;
    list-style-position: inside;
    padding: 2px 0;
}
.thinking-process[open] summary {
    margin-bottom: 8px;
    border-bottom: 1px solid #e0e6ec;
    padding-bottom: 5px;
}
.collapsible-content p, .collapsible-content pre {
    margin: 4px 0 4px 5px;
    padding: 0;
    line-height: 1.3;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.collapsible-content .tool-call {
    color: #2a6f7a;
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.95em;
}
.collapsible-content .tool-result {
    color: #4a6a4a;
}
.collapsible-content .tool-error {
    color: #b03030;
}

/* --- Input area --- */
.input-area {
    display: flex;
    padding: 15px;
    background-color: #f8f9fa;
    gap: 8px;
}

#userInput {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 20px;
    resize: none;
    min-height: 20px;
    max-height: 100px;
    overflow-y: auto;
    font-family: inherit;
    font-size: 14px;
}

#sendButton, #cancelButton {
    padding: 10px 18px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    color: white;
    font-size: 14px;
}

#sendButton {
    background-color: #28a745;
}
#sendButton:hover { background-color: #218838; }
#sendButton:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

#cancelButton {
    background-color: #dc3545;
}
#cancelButton:hover { background-color: #c82333; }

/* --- Scrollbar --- */
.chat-box::-webkit-scrollbar { width: 8px; }
.chat-box::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 10px; }
.chat-box::-webkit-scrollbar-thumb { background: #888; border-radius: 10px; }
.chat-box::-webkit-scrollbar-thumb:hover { background: #555; }

/* --- Code blocks in markdown --- */
.bot-message pre, .collapsible-content pre {
    background-color: #2d2d2d;
    color: #f8f8f2;
    padding: 0.6em 0.8em;
    border-radius: 0.3em;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.85em;
}
.bot-message code, .collapsible-content code {
    background-color: #f0f0f0;
    color: #b03030;
    padding: 0 4px;
    border-radius: 3px;
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.9em;
}
.bot-message pre code, .collapsible-content pre code {
    background: none;
    color: inherit;
    padding: 0;
}

/* --- Top bar (identifier + session controls) --- */
.user-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f7f7f8;
    border-bottom: 1px solid #e5e5e7;
    font-size: 13px;
}
.user-bar-label {
    color: #555;
    font-weight: 500;
}
.user-bar input {
    min-width: 180px;
    padding: 6px 8px;
    border: 1px solid #d0d0d4;
    border-radius: 4px;
    font-size: 13px;
    background: #fff;
}
.user-bar button {
    padding: 4px 10px;
    height: 26px;
    border: 1px solid #d0d0d4;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    color: #555;
    font-size: 12px;
}
.user-bar button:hover { background: #ececef; color: #222; }
#clearUserIdButton {
    width: 24px;
    height: 24px;
    padding: 0;
    line-height: 1;
}
.user-bar-status {
    font-size: 12px;
    color: #777;
    white-space: nowrap;
}
.user-bar-status-ok { color: #2a7a4a; }
.user-bar-status-warn { color: #b9612b; }
.user-bar-spacer { flex: 1; }
.user-bar-session {
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 11px;
    color: #595959;
    background: #fff;
    padding: 4px 8px;
    border: 1px solid #e5e5e7;
    border-radius: 4px;
}

/* --- TeamLease credentials panel --- */
.tl-creds-bar {
    background: #f7f4ff;
    border-bottom: 1px solid #ddd0f5;
    font-size: 13px;
    color: #444;
}
.tl-creds-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    cursor: pointer;
    font-weight: 500;
    list-style: none;
    outline: none;
    user-select: none;
}
.tl-creds-summary::-webkit-details-marker { display: none; }
.tl-creds-summary::before {
    content: '▶';
    font-size: 10px;
    color: #888;
    transition: transform 0.15s;
}
.tl-creds-bar[open] .tl-creds-summary::before {
    transform: rotate(90deg);
}
.tl-creds-badge {
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
    font-weight: 400;
}
.tl-creds-badge-ok   { background: #d4edda; color: #1a5e38; }
.tl-creds-badge-warn { background: #fff3cd; color: #7a5000; }

.tl-creds-fields {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 10px 16px 12px;
    border-top: 1px solid #ddd0f5;
}
.tl-field {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #555;
    white-space: nowrap;
}
.tl-field input {
    padding: 5px 8px;
    border: 1px solid #c8b8f0;
    border-radius: 4px;
    font-size: 12px;
    background: #fff;
    width: 180px;
}
.tl-field input:focus {
    outline: none;
    border-color: #7c4dff;
    box-shadow: 0 0 0 2px rgba(124,77,255,0.15);
}
#tlSaveButton, #tlClearButton {
    padding: 5px 12px;
    border-radius: 4px;
    border: 1px solid #c8b8f0;
    cursor: pointer;
    font-size: 12px;
}
#tlSaveButton  { background: #7c4dff; color: #fff; border-color: #7c4dff; }
#tlSaveButton:hover  { background: #6a3ddf; }
#tlClearButton { background: #fff; color: #555; }
#tlClearButton:hover { background: #f0ecff; }

/* Agent-key (X-Agent-Key) panel — reuses the tl-creds layout but a neutral
   slate accent to signal it's the machine-gate secret, not user creds. */
.agent-key-bar {
    background: #f4f6f8;
    border-bottom: 1px solid #d4dae0;
}
.agent-key-bar .tl-creds-fields { border-top-color: #d4dae0; }
.agent-key-bar .tl-field input { border-color: #b7c2cd; width: 220px; }
.agent-key-bar .tl-field input:focus {
    border-color: #4a6076;
    box-shadow: 0 0 0 2px rgba(74,96,118,0.15);
}
#agentKeySaveButton, #agentKeyClearButton {
    padding: 5px 12px;
    border-radius: 4px;
    border: 1px solid #b7c2cd;
    cursor: pointer;
    font-size: 12px;
}
#agentKeySaveButton { background: #4a6076; color: #fff; border-color: #4a6076; }
#agentKeySaveButton:hover { background: #3b4e60; }
#agentKeyClearButton { background: #fff; color: #555; }
#agentKeyClearButton:hover { background: #eef1f4; }
.agent-key-hint { font-size: 11px; color: #88929c; }

/* --- Blinking cursor while streaming --- */
.blinking-cursor {
    display: inline-block;
    width: 8px;
    height: 1em;
    background-color: #333;
    animation: blink-animation 1s steps(2, start) infinite;
    vertical-align: text-bottom;
}
@keyframes blink-animation {
    to { visibility: hidden; }
}
