/* The AI chat panel, shared by the Reactive Editor (asset_editor/index.php) and the
   project editor (index.php): a fixed panel at the right edge that slides out from
   its tab. Colours come from the theme variables in themes.css. (Sizes are in px:
   the two pages have different root font sizes.) */
/* =========================================================================
   AI (live code) panel. 662.4px wide; closed, it shows a 44px tab.
   ========================================================================= */
.live-code-container {
    position: fixed;
    top: 84px;
    right: 0px;
    width: 662.4px;
    height: 684px;
    max-height: calc(100vh - 92px);         /* (fits a short window: the chat shrinks) */
    z-index: 1040;                          /* over the editors' panels, under dialogs (1050+) */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    overflow: hidden;
    background: var(--t-ai-bg);
    backdrop-filter: var(--t-bar-filter);
    -webkit-backdrop-filter: var(--t-bar-filter);
    border: 1px solid var(--t-bar-edge);
    border-right: none;
    border-radius: 4px 0 0 4px;
    box-shadow: var(--t-ai-shadow);
    color: var(--t-text);
    font: 13px/1.45 var(--t-font);
    transition: right 0.3s ease, height 0.3s ease;
}
.live-code-closed { right: -618px !important; }
.live-code-arrow-clicked { transform: rotateZ(180deg) !important; }
/* Closed: shrink to the header so only the AI tab shows at the edge */
.live-code-container.live-code-closed { height: 44px; }
.live-code-container.live-code-closed #live-code-chat-history,
.live-code-container.live-code-closed #live-code-input-area { visibility: hidden; }
.live-code-container *:not(i) { font-family: var(--t-font); }

/* Header */
.icons-live-code {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-shrink: 0;
    width: 100%;
    height: 44px;
    gap: 4px;
    padding-right: 12px;
    background: var(--t-ai-header-bg);
    border-bottom: 1px solid var(--t-line);
    color: var(--t-text);
}
.icons-live-code div {
    display: flex;
    justify-content: center;
    align-items: center;
    width: auto;
    height: auto;
    padding: 0;
    background-color: transparent;
    font-size: 14px;
    color: var(--t-text);
    cursor: pointer;
    transition: transform 0.3s ease, color 0.15s ease;
}
.icons-live-code div:hover { color: var(--t-hover-text); }
/* The tab that stays visible when the panel is closed */
.icons-live-code .lc-tab {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    flex-direction: column;
    gap: 2px;
    border-right: 1px solid var(--t-line);
}
.icons-live-code .lc-tab-label {
    color: var(--t-ai-accent);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}
#live-code-refresh {
    width: 28px !important;
    height: 28px !important;
    margin-left: 6px;
    border: 1px solid var(--t-btn-border);
    border-radius: 3px;
    background: var(--t-surface);
    font-size: 12px !important;
}
#live-code-refresh:hover { background: var(--t-surface-hi); border-color: var(--t-btn-hover-border); }
.lc-title {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 0 8px;
    color: var(--t-text-strong);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lc-title #ai_txt { color: var(--t-text-dim); font-size: 12px; cursor: help; }
.lc-title #ai_txt:hover { color: var(--t-hover-text); }

/* Conversation */
#live-code-chat-history {
    width: 660px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--t-scroll-thumb) transparent;
}
.chat-message-user,
.chat-message-ai {
    max-width: 85%;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.chat-message-user {
    align-self: flex-end;
    background: var(--t-msg-user-bg);
    color: var(--t-msg-user-text);
    border: var(--t-msg-user-border);
    border-radius: 8px 8px 2px 8px;
}
.chat-message-ai {
    align-self: flex-start;
    background: var(--t-msg-ai-bg);
    color: var(--t-msg-ai-text);
    border-left: 2px solid var(--t-accent);
    border-radius: 2px 8px 8px 8px;
}
.chat-file-block {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding: 6px 10px;
    background: var(--t-file-bg);
    border: 1px solid var(--t-file-border);
    border-radius: 3px;
    color: var(--t-file-text);
    font-size: 12px;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}
.chat-file-block:hover { border-color: var(--t-ai-accent); color: var(--t-text-strong); }
.chat-file-block i { color: var(--t-ai-accent); }

/* Input area */
#live-code-input-area {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: 660px;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--t-line);
    background: var(--t-ai-header-bg);
}
.live-code-input-top { display: flex; align-items: flex-end; gap: 8px; }
#live-code-input {
    flex: 1;
    resize: none;
    background: var(--t-field-bg);
    color: var(--t-field-text);
    border: 1px solid var(--t-field-border);
    border-radius: 3px;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.45;
    color-scheme: var(--t-field-scheme);
    transition: border-color 0.15s ease;
}
#live-code-input::placeholder { color: var(--t-field-placeholder); }
#live-code-input:focus {
    outline: none;
    background: var(--t-ai-field-focus-bg);
    border-color: var(--t-ai-focus-border);
    box-shadow: var(--t-ai-input-ring);
}
#live-code-input:hover { background: var(--t-ai-field-hover-bg); border-color: var(--t-ai-field-hover-border); }
#live-code-input:hover:focus { border-color: var(--t-ai-focus-border); }
#live-code-send {
    width: 40px;
    height: 34px;
    padding: 0;
    background: var(--t-accent);
    color: var(--t-accent-text);
    border: none;
    border-radius: 3px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}
#live-code-send:hover { background: var(--t-accent-hi); }
#live-code-send:focus-visible { outline: none; box-shadow: 0 0 0 2px #F0BC22; }

#live-code-mode-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 0;
    font-size: 12px;
}
.live-code-mode-label { color: var(--t-text); font-size: 12px; font-weight: 400; }
.live-code-mode-select {
    height: 26px;
    padding: 0 6px;
    background: var(--t-field-bg);
    color: var(--t-field-text);
    border: 1px solid var(--t-field-border);
    border-radius: 3px;
    font-size: 12px;
    color-scheme: var(--t-field-scheme);
    cursor: pointer;
    outline: none;
}
.live-code-mode-select:focus {
    background: var(--t-ai-field-focus-bg);
    border-color: var(--t-ai-focus-border);
    box-shadow: var(--t-ai-select-ring);
}
.live-code-mode-select:hover { background: var(--t-ai-field-hover-bg); border-color: var(--t-ai-field-hover-border); }
.live-code-mode-select option { background: var(--t-option-bg); color: var(--t-option-text); }
.live-code-mode-hint { flex: 1; color: var(--t-text-dim); font-size: 11px; font-style: normal; }

/* AI panel: Detail slider (Simple, Balanced, Rich) */
#live-code-detail-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; }
.lc-detail-label { min-width: 34px; }
.lc-detail-track { display: flex; flex-direction: column; width: 190px; flex: none; }
.lc-detail-slider { width: 100%; margin: 0; accent-color: var(--t-accent); cursor: pointer; }
.lc-detail-ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--t-text-dim); }
.lc-detail-tick { cursor: pointer; }
.lc-detail-tick.selected { color: var(--t-text); font-weight: 600; }

/* AI panel: Style (under Mode): a row of style icons, its description and its five colours */
#live-code-style-row { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; font-size: 12px; }
.lc-style-icons { display: flex; flex-wrap: wrap; gap: 5px; }
.lc-style-btn {
    width: 38px; height: 38px; padding: 0; border-radius: 5px; cursor: pointer; overflow: hidden;
    background: var(--t-field-bg); border: 1px solid var(--t-field-border);
}
.lc-style-btn img { width: 100%; height: 100%; display: block; }
.lc-style-btn:hover { border-color: var(--t-ai-field-hover-border); }
.lc-style-btn.selected { outline: 2px solid var(--t-accent); outline-offset: 1px; border-color: var(--t-accent); }
.lc-style-none { color: var(--t-text); font-size: 11px; }
.lc-style-desc { color: var(--t-text-dim); font-size: 11px; line-height: 1.35; }
.lc-style-desc b { color: var(--t-text); font-weight: 600; }
.lc-style-swatches { display: flex; align-items: center; gap: 5px; }
.lc-style-swatch { width: 30px; height: 22px; padding: 0 1px; border: 1px solid var(--t-field-border); border-radius: 3px; background: none; cursor: pointer; }
.lc-style-swatches.lc-style-off .lc-style-swatch { opacity: 0.35; }
.lc-style-reset { height: 22px; padding: 0 8px; font-size: 11px; border-radius: 3px; cursor: pointer;
    background: var(--t-field-bg); color: var(--t-field-text); border: 1px solid var(--t-field-border); }
.lc-style-own { display: flex; align-items: center; gap: 4px; color: var(--t-text); font-size: 11px; margin: 0 0 0 4px; cursor: pointer; }
.chat-style-chip { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 8px; font-size: 10px;
    background: var(--t-surface-hi); color: var(--t-text-dim); vertical-align: middle; }

/* AI panel on narrow screens: fit the width instead of running off-screen */
@media (max-width: 820px) {
    .live-code-container {
        width: min(662.4px, calc(100vw - var(--sp-rail, 0px)));
        height: auto;
        max-height: calc(100% - 84px - 8px);
    }
    .live-code-container.live-code-closed {
        right: calc(44.4px - min(662.4px, calc(100vw - var(--sp-rail, 0px)))) !important;
    }
    #live-code-chat-history,
    #live-code-input-area { width: 100%; }
    #live-code-chat-history { padding: 16px; }
}

.live-code-mode-select:hover:focus { border-color: var(--t-ai-focus-border); }

/* The chat's text can be selected and copied; each prompt has a copy button */
.chat-message-user, .chat-message-ai { user-select: text; -webkit-user-select: text; cursor: text; }
.chat-copy-btn { display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
                 margin-left: 6px; padding: 3px; border: none; border-radius: 4px; background: transparent;
                 color: inherit; opacity: 0.55; cursor: pointer; line-height: 0; }
.chat-copy-btn:hover, .chat-copy-btn:focus-visible { opacity: 1; background: rgba(127, 127, 127, 0.18); }
.chat-copy-btn.copied { opacity: 1; color: #2a9d8f; }

/* A design's Undo, inside its box (Build mode's AI, DesignAI.js) */
.chat-undo-btn { margin-left: auto; padding: 2px 10px; border-radius: 4px; border: 1px solid var(--t-btn-border, rgba(127, 127, 127, 0.4));
    background: transparent; color: inherit; font-size: 12px; cursor: pointer; }
.chat-undo-btn:hover:not(:disabled) { background: rgba(127, 127, 127, 0.18); }
.chat-undo-btn:disabled { opacity: 0.6; cursor: default; }
.chat-design-preview { display: block; max-width: 160px; max-height: 160px; margin-top: 6px; border-radius: 4px;
    background: repeating-conic-gradient(rgba(127, 127, 127, 0.25) 0 25%, transparent 0 50%) 0 0 / 16px 16px; }
/* What the next request costs (aiPrices.js), under the message box, and each detail level's price */
.lc-price { margin: 4px 2px 2px; font-size: 12px; color: var(--t-text-dim); }
.lc-price b { color: var(--t-ai-accent, #2a9d8f); font-weight: 700; }
.lc-detail-tick .lc-detail-price { display: block; font-size: 10px; opacity: 0.75; line-height: 1.1; }
