/* ===== Agentic designer assistant chat panel =====
   Shipped with Kailo.Modules.AgenticDesigner.UI and served from
   _content/Kailo.Modules.AgenticDesigner.UI/ai-chat.css, so every host that embeds
   AssistantChatPanel gets identical styling. Dark-mode rules key off [data-theme="dark"]
   on <html>, which both Kailo Flow and the Portal set. ===== */

.ai-chat-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    font-size: 0.85rem;
    color: #1f2937;
}

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-bottom: 1px solid #e0e0e0;
    flex: 0 0 auto;
}

.ai-chat-title {
    font-weight: 600;
}

.ai-header-actions {
    display: flex;
    gap: 2px;
}

.ai-icon-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 6px;
    border-radius: 4px;
}

.ai-icon-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.ai-icon-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* History drawer */
.ai-history {
    flex: 0 0 auto;
    max-height: 180px;
    overflow-y: auto;
    border-bottom: 1px solid #e0e0e0;
    padding: 6px 8px;
}

.ai-history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    gap: 8px;
}

.ai-history-title {
    font-weight: 500;
}

/* Messages */
.ai-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    width: 100%;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
    min-width: 0;
}

.message-role {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.3rem;
    opacity: 0.7;
}

.assistant-message .message-role {
    color: #0d6efd;
}

.user-message .message-role {
    color: #0a3275;
}

.message-body {
    min-width: 0;
}

/* User messages stay in a highlighted card to anchor them visually. */
.user-message .message-body {
    background: #eaf2ff;
    color: #0a3275;
    border: 1px solid #cfe0ff;
    border-radius: 0.75rem;
    padding: 0.6rem 0.8rem;
}

/* Assistant messages are FLAT — no bubble. Text, thinking and sub-agent cards stack vertically. */
.assistant-message .message-body {
    background: transparent;
    padding: 0;
}

.message-content {
    overflow-wrap: break-word;
}

.message-content + .message-content {
    margin-top: 0.4rem;
}

/* Markdown-rendered blocks — tight, readable spacing inside chat bubbles/cards. */
.message-content > :first-child,
.planner-thinking-body > :first-child {
    margin-top: 0;
}

.message-content > :last-child,
.planner-thinking-body > :last-child {
    margin-bottom: 0;
}

.message-content p,
.planner-thinking-body p {
    margin: 0 0 0.5rem;
}

.message-content ul,
.message-content ol,
.planner-thinking-body ul,
.planner-thinking-body ol {
    margin: 0 0 0.5rem;
    padding-left: 1.3rem;
}

.message-content li,
.planner-thinking-body li {
    margin: 0.1rem 0;
}

.message-content pre,
.planner-thinking-body pre {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    overflow-x: auto;
    font-size: 0.78rem;
}

.message-content code,
.planner-thinking-body code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.82em;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.05rem 0.3rem;
    border-radius: 3px;
}

.message-content pre code,
.planner-thinking-body pre code {
    background: transparent;
    padding: 0;
}

.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6,
.planner-thinking-body h1, .planner-thinking-body h2, .planner-thinking-body h3,
.planner-thinking-body h4, .planner-thinking-body h5, .planner-thinking-body h6 {
    margin: 0.6rem 0 0.3rem;
    font-size: 0.95rem;
    font-weight: 600;
}

.message-content table,
.planner-thinking-body table {
    border-collapse: collapse;
    margin: 0 0 0.5rem;
    font-size: 0.8rem;
}

.message-content th, .message-content td,
.planner-thinking-body th, .planner-thinking-body td {
    border: 1px solid rgba(0, 0, 0, 0.15);
    padding: 0.2rem 0.4rem;
}

.ai-status {
    font-style: italic;
    color: #666;
    padding: 2px 0;
}

/* ── Coloured agent cards (planner / researcher / executor) ─────────────────── */
.subagent-card {
    margin: 0.4rem 0;
    padding: 0.5rem 0.75rem;
    border-radius: 0.4rem;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-left-width: 3px;
    font-size: 0.85rem;
}

.subagent-card.researcher {
    background: #eef4ff;
    border-left-color: #4a7bd6;
}

.subagent-card.executor {
    background: #effaef;
    border-left-color: #4ca74c;
}

.subagent-card.planner {
    background: #fff7e6;
    border-left-color: #d4a04a;
}

.subagent-card.planner.streaming {
    box-shadow: 0 0 0 1px rgba(212, 160, 74, 0.22);
}

.planner-thinking-body {
    margin: 0.4rem 0 0;
    padding: 0.45rem 0.6rem;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 3px;
    color: #4b4332;
    font-size: 0.82rem;
    line-height: 1.5;
    overflow-wrap: break-word;
    max-height: 22rem;
    overflow-y: auto;
}

/* Shown when the planner streamed no reasoning at all — quieter than real thinking, because it is an
   explanation of an absence rather than content. */
.planner-thinking-empty {
    font-style: italic;
    opacity: 0.75;
}

.planner-thinking-headline {
    color: #6b5224;
    font-weight: 500;
    font-size: 0.78rem;
}

.subagent-head {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    cursor: pointer;
    list-style: none;
}

.subagent-head::-webkit-details-marker {
    display: none;
}

.subagent-head-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.thinking-chevron {
    display: inline-block;
    font-size: 0.7rem;
    color: #888;
    transition: transform 0.15s ease;
}

.subagent-card[open] > .subagent-head .thinking-chevron {
    transform: rotate(90deg);
}

.subagent-label {
    font-weight: 600;
    color: #2c3340;
}

.subagent-meta {
    font-size: 0.72rem;
    color: #5b6470;
    background: rgba(255, 255, 255, 0.55);
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
}

.subagent-spinner {
    width: 0.8em;
    height: 0.8em;
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-top-color: #000;
    border-radius: 50%;
    display: inline-block;
    animation: ai-spin 0.7s linear infinite;
}

@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

.subagent-section {
    margin-top: 0.4rem;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.subagent-section > summary {
    padding: 0.3rem 0.5rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: #2c3340;
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.subagent-section > summary::-webkit-details-marker {
    display: none;
}

.subagent-section > summary:hover {
    background: rgba(0, 0, 0, 0.03);
}

.subagent-pre {
    margin: 0;
    padding: 0.4rem 0.6rem;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.74rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    color: #333;
    max-height: 18rem;
    overflow-y: auto;
}

.subagent-pre.subagent-thinking {
    background: #faf7f0;
    color: #4a4030;
}

.subagent-toolcalls {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.35rem;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.subagent-toolcall {
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 3px;
    background: #fafbfc;
}

.subagent-toolcall.error {
    border-color: #d9534f;
    background: #fdf3f3;
}

.subagent-toolcall > summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    font-size: 0.76rem;
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.subagent-toolcall > summary::-webkit-details-marker {
    display: none;
}

.subagent-toolcall > summary:hover {
    background: rgba(0, 0, 0, 0.025);
}

.subagent-tool-name {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-weight: 600;
    color: #2c3340;
}

.subagent-tool-flag {
    font-size: 0.68rem;
    color: #b3211f;
    background: #ffe1e0;
    padding: 0.05rem 0.35rem;
    border-radius: 999px;
}

.subagent-tool-dur {
    margin-left: auto;
    font-size: 0.7rem;
    color: #6a737d;
}

.subagent-toolcall-body {
    padding: 0.3rem 0.5rem 0.4rem;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.subagent-toolcall-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6a737d;
    margin-top: 0.3rem;
    margin-bottom: 0.15rem;
}

.subagent-toolcall-label:first-child {
    margin-top: 0;
}

/* Changes / diff expander */
.ai-changes {
    margin-top: 6px;
}

.ai-changes > summary {
    cursor: pointer;
    color: #666;
    font-size: 0.8rem;
}

.ai-change-label {
    font-weight: 600;
    font-size: 0.8rem;
    margin-top: 6px;
}

.ai-diff {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.74rem;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 4px;
    padding: 4px;
    overflow-x: auto;
}

.ai-diff-line { white-space: pre; }
.ai-diff-added { background: rgba(46, 160, 67, 0.15); }
.ai-diff-removed { background: rgba(192, 57, 43, 0.15); }
.ai-diff-context { color: #888; }
.ai-add { color: #2ea043; }
.ai-rem { color: #c0392b; }

/* Banners */
.ai-banner {
    flex: 0 0 auto;
    padding: 6px 10px;
    font-size: 0.8rem;
}

.ai-error-banner {
    background: #f7e7e6;
    color: #c0392b;
}

/* Usage footer — one full-width bar, month-to-date against the monthly AI budget. Every figure lives in its
   tooltip; nothing is printed beside it, so the bar spans the panel. */
.ai-usage {
    flex: 0 0 auto;
    padding: 6px 8px;
    border-top: 1px solid #e0e0e0;
    cursor: help;
}

/* Slim, because this sits under a two-line message box in the narrowest column on the page and a
   full-height bar there reads as a loading indicator for the chat rather than a budget gauge. */
.ai-usage-bar {
    height: 6px;
    width: 100%;
}

.ai-muted {
    color: #888;
}

/* Input — one row: message box grows, send/stop keeps its natural width beside it. */
.ai-input {
    flex: 0 0 auto;
    padding: 8px;
    border-top: 1px solid #e0e0e0;
}

/* Width comes from the stack item it sits in, not from being a flex child itself. */
.ai-input textarea {
    width: 100%;
    resize: vertical;
    font-family: inherit;
    font-size: 0.85rem;
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 6px;
}

.ai-btn {
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
    font-weight: 600;
    color: #fff;
}

.ai-send { background: #7a5cff; }
.ai-send:disabled { background: #b9b9b9; cursor: default; }
.ai-stop { background: #c0392b; }

.ai-link {
    border: none;
    background: transparent;
    color: #7a5cff;
    cursor: pointer;
    font-size: 0.8rem;
}

/* ── Dark mode ──────────────────────────────────────────────────────────────
   The coloured agent cards (planner/researcher/executor) get dark tints that keep their accent
   colour, and every surface nested inside them (thinking body, sections, tool-call panels, pre
   blocks, cost chips) is re-skinned dark with light text so nothing stays black-on-white. */
[data-theme="dark"] .ai-chat-panel {
    color: #dcdcdc;
}

/* The assistant's response text is the primary output — keep it bright. */
[data-theme="dark"] .assistant-message .message-content {
    color: #f4f4f5;
}

/* The light card backgrounds (user bubble + planner/researcher/executor) wash out on the dark page;
   give each a dark tint that keeps its accent colour readable. */
[data-theme="dark"] .user-message .message-body {
    background: #18283f;
    color: #dce7f7;
    border-color: #2e496b;
}

[data-theme="dark"] .subagent-card {
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .subagent-card.researcher {
    background: #16243a;
}

[data-theme="dark"] .subagent-card.executor {
    background: #142719;
}

[data-theme="dark"] .subagent-card.planner {
    background: #3a2410;
}

[data-theme="dark"] .planner-thinking-body {
    background: #46311e;
    border-color: rgba(255, 255, 255, 0.12);
    color: #eef0f3;
}

[data-theme="dark"] .planner-thinking-headline {
    color: #f0c98a;
}

/* Card headings ("Planned"/"Researched"/"Executed", section + tool names) need to pop on the dark
   card backgrounds. */
[data-theme="dark"] .subagent-label,
[data-theme="dark"] .subagent-section > summary,
[data-theme="dark"] .subagent-tool-name {
    color: #eef1f5;
}

[data-theme="dark"] .subagent-meta {
    color: #c3cad3;
    background: #34373c;
}

/* The in-progress spinner beside "Planning…" / "Researching…" / "Executing…": white on the dark page, where
   the light theme's black ring all but disappears. */
[data-theme="dark"] .subagent-spinner {
    border-color: rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
}

[data-theme="dark"] .subagent-toolcall-label,
[data-theme="dark"] .subagent-tool-dur {
    color: #9aa3ad;
}

/* Input / tool calls / output panels inside the researcher & executor cards default to light
   (white pre blocks, near-white sections) — give them a dark surface with light text. */
[data-theme="dark"] .subagent-section {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.10);
}

[data-theme="dark"] .subagent-section > summary:hover,
[data-theme="dark"] .subagent-toolcall > summary:hover {
    background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .subagent-pre {
    background: #1f2329;
    border-top-color: rgba(255, 255, 255, 0.10);
    color: #d6dade;
}

[data-theme="dark"] .subagent-pre.subagent-thinking {
    background: #241f17;
    color: #e7ddca;
}

[data-theme="dark"] .subagent-toolcalls {
    background: rgba(255, 255, 255, 0.03);
    border-top-color: rgba(255, 255, 255, 0.10);
}

[data-theme="dark"] .subagent-toolcall {
    background: #22262c;
    border-color: rgba(255, 255, 255, 0.10);
}

[data-theme="dark"] .subagent-toolcall.error {
    background: #2e1b1b;
    border-color: #d9534f;
}

[data-theme="dark"] .subagent-toolcall-body {
    border-top-color: rgba(255, 255, 255, 0.10);
}

[data-theme="dark"] .subagent-tool-flag {
    background: #3a1f1f;
    color: #ff8a87;
}

[data-theme="dark"] .ai-chat-header,
[data-theme="dark"] .ai-history,
[data-theme="dark"] .ai-usage,
[data-theme="dark"] .ai-input {
    border-color: rgba(255, 255, 255, 0.14);
}

[data-theme="dark"] .assistant-message .message-role {
    color: #5b9bff;
}

[data-theme="dark"] .user-message .message-role {
    color: #8fb6ff;
}

[data-theme="dark"] .ai-status,
[data-theme="dark"] .ai-changes > summary,
[data-theme="dark"] .ai-usage {
    color: #a8aeb5;
}

[data-theme="dark"] .ai-muted,
[data-theme="dark"] .ai-diff-context {
    color: #8a8a8a;
}

[data-theme="dark"] .ai-input textarea {
    background: #2b2b2b;
    color: #e0e0e0;
    border-color: #555;
}

/* Header icon buttons (new session / export / history) need a light colour in dark mode. */
[data-theme="dark"] .ai-icon-btn { color: #cfd8e3; }
[data-theme="dark"] .ai-icon-btn:hover { color: #fff; background: #33363b; }
