/* Copilot chat-bubble widget: a floating action button that toggles a
   compact, non-blocking chat popup anchored to the bottom-right corner. */

.copilot-bubble {
    position: fixed;
    bottom: 6px;
    right: 6px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    z-index: 1045;
    background: #23242b;
    border: 1px solid rgba(var(--bs-primary-rgb), .45);
    color: rgb(var(--bs-primary-rgb));
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .35);
    transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.copilot-bubble:hover {
    transform: translateY(-1px);
    border-color: rgb(var(--bs-primary-rgb));
    box-shadow: 0 4px 16px rgba(var(--bs-primary-rgb), .3);
}

.copilot-bubble:focus {
    outline: none;
}

html[data-theme="light"] .copilot-bubble {
    background: var(--surface-0);
    box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}

.copilot-popup {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 550px;
    max-width: calc(100vw - 48px);
    height: 680px;
    max-height: calc(100vh - 48px);
    z-index: 1045;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #1e1f25;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
    transform-origin: bottom right;
    transform: translateY(12px) scale(.98);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}

.copilot-popup.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* The bubble is a launcher only — hide it while the popup is open so the
   panel never overlaps its own trigger. */
#copilot-popup.open ~ #copilot-bubble {
    display: none;
}

/* Small screens: full-screen takeover so the panel doesn't float above the
   launcher in the bottom-right corner. */
/*noinspection CssNonIntegerLengthInPixels*/
@media (max-width: 575.98px) {
    .copilot-popup {
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
        border: none;
    }
}

/* User-toggled full-screen (persisted in localStorage). Same takeover as the
   small-screen rule, but on demand at any width. */
.copilot-popup.expanded {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
}

/* Expand/compress icon reflects the popup's state with no JS icon swapping. */
.copilot-icon-compress {
    display: none;
}

.copilot-popup.expanded .copilot-icon-expand {
    display: none;
}

.copilot-popup.expanded .copilot-icon-compress {
    display: inline;
}

#copilot-popup-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
}

#copilot-popup-body > * {
    width: 100%;
}

html[data-theme="light"] .copilot-popup {
    background: var(--surface-0);
    border-color: var(--border-emphasis);
    box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
}

/* Popup header: tinted icon tile + a tracked "COPILOT" label over the
   active domain. */
.copilot-header {
    flex-shrink: 0;
    background: rgba(255, 255, 255, .06);
    border-bottom: 1px solid var(--border-emphasis);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
    z-index: 1;
}

/* Footer input bar: same elevated-chrome treatment as the header so the
   message list reads as scrolling under both, not blending into them. */
.copilot-footer {
    flex-shrink: 0;
    background: rgba(255, 255, 255, .06);
    border-top: 1px solid var(--border-emphasis);
    box-shadow: 0 -2px 6px rgba(0, 0, 0, .25);
    z-index: 1;
}

html[data-theme="light"] .copilot-header {
    background: rgba(0, 0, 0, .03);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .06);
}

html[data-theme="light"] .copilot-footer {
    background: rgba(0, 0, 0, .03);
    box-shadow: 0 -2px 6px rgba(0, 0, 0, .06);
}

.copilot-header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    flex-shrink: 0;
    font-size: 1rem;
    color: rgb(var(--bs-primary-rgb));
    background: rgba(var(--bs-primary-rgb), .16);
}

.copilot-header-title {
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .12em;
    line-height: 1.2;
    color: var(--text-primary);
}

.copilot-header-domain {
    font-size: .72rem;
    line-height: 1.3;
    color: var(--text-secondary);
}

/* Header action toolbar: a row of uniform, borderless icon buttons
   (new chat, usage, minimize) so nothing reads as odd-one-out. */
.copilot-header-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    line-height: 1;
    cursor: pointer;
    transition: color .12s ease, background .12s ease;
}

.copilot-header-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, .06);
}

html[data-theme="light"] .copilot-header-btn:hover {
    background: rgba(0, 0, 0, .05);
}

.copilot-header-actions {
    gap: .25rem;
}

/* Conversation history overlay: a resume row + a staff usage button. */
.copilot-convo {
    display: flex;
    align-items: center;
    gap: .25rem;
    border-radius: 8px;
}

.copilot-convo:hover {
    background: rgba(255, 255, 255, .05);
}

html[data-theme="light"] .copilot-convo:hover {
    background: rgba(0, 0, 0, .04);
}

.copilot-convo--current {
    background: rgba(var(--bs-primary-rgb), .1);
}

.copilot-convo-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: .15rem;
    text-align: left;
    padding: .5rem .625rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
}

.copilot-convo-usage {
    flex-shrink: 0;
    margin-right: .375rem;
}

.copilot-convo-title {
    font-size: .85rem;
    font-weight: 600;
}

.copilot-convo-meta {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .72rem;
    color: var(--text-secondary);
}

.copilot-convo-usage-line {
    font-size: .68rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* Tools reference overlay (staff): one row per registered tool. */
.copilot-tool {
    padding: .625rem 0;
    border-bottom: 1px solid var(--border-normal);
}

.copilot-tool:last-child {
    border-bottom: none;
}

.copilot-tool-name {
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.copilot-tool-desc {
    white-space: pre-line;
}

.copilot-tool-schema-toggle {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: .8rem;
}

.copilot-tool-schema {
    margin: .5rem 0 0;
    padding: .75rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, .04);
    max-height: 24rem;
    overflow: auto;
    font-size: .8rem;
}

html[data-theme="light"] .copilot-tool-schema {
    background: rgba(0, 0, 0, .035);
}

/* Staff session-usage overlay: an opaque takeover of the whole panel with
   its own header, so LLM cost/token diagnostics don't disturb the chat. */
#copilot-panel {
    position: relative;
}

.copilot-session-info {
    position: absolute;
    inset: 0;
    z-index: 3;
    background: #1e1f25;
}

.copilot-session-info:empty {
    display: none;
}

html[data-theme="light"] .copilot-session-info {
    background: var(--surface-0);
}

.copilot-usage-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
}

.copilot-usage-stat {
    display: flex;
    flex-direction: column;
    padding: .5rem .625rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, .04);
}

html[data-theme="light"] .copilot-usage-stat {
    background: rgba(0, 0, 0, .035);
}

.copilot-usage-label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-secondary);
}

.copilot-usage-value {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.copilot-usage-req {
    padding: .5rem 0;
    border-bottom: 1px solid var(--border-normal);
    color: var(--text-primary);
}

.copilot-usage-req:last-child {
    border-bottom: none;
}

.copilot-usage-req-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .5rem;
}

.copilot-usage-req-label {
    font-weight: 600;
    min-width: 0;
}

.copilot-usage-req-cost {
    color: var(--text-primary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.copilot-usage-req-sub {
    margin-top: .1rem;
    font-size: .72rem;
    color: var(--text-secondary);
}

/* Token counts as small labeled cells, tabular so columns line up down
   the list. */
.copilot-usage-req-tokens {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem .75rem;
    margin-top: .35rem;
    font-size: .74rem;
    font-variant-numeric: tabular-nums;
}

.copilot-usage-req-tokens .tok-label {
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: .62rem;
    letter-spacing: .04em;
}

.copilot-usage-req-error {
    margin-top: .35rem;
    font-size: .72rem;
    word-break: break-word;
}

/* Changeset (apply/confirm) block: a light, flat container that reads as a
   section of the assistant message rather than a heavy nested card. */
.copilot-changeset {
    border-radius: 8px;
    padding: .5rem .625rem;
    background: rgba(255, 255, 255, .04);
}

html[data-theme="light"] .copilot-changeset {
    background: rgba(0, 0, 0, .035);
}

.copilot-cs-status {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}

.copilot-cs-actions li,
.copilot-cs-results li {
    line-height: 1.35;
}

/* Long action/result lists get their own quiet scroll area instead of
   stretching the whole conversation. */
.copilot-cs-actions,
.copilot-cs-results {
    max-height: 8.5rem;
    overflow-y: auto;
}
