/* Global Project Copilot shell. Conversation behavior is intentionally separate. */

.app-shell {
    min-height: 100dvh;
}

.copilot-shell {
    --copilot-bubble-width: clamp(360px, 30vw, 440px);
    position: fixed;
    z-index: 90;
    right: max(20px, env(safe-area-inset-right, 0px));
    bottom: max(20px, env(safe-area-inset-bottom, 0px));
    width: var(--copilot-bubble-width);
    height: min(720px, 74dvh, calc(100dvh - 40px));
    pointer-events: none;
    visibility: hidden;
    color: var(--text-1);
    transition:
        visibility 0s linear var(--dur);
}

.copilot-shell.is-open {
    visibility: visible;
    transition-delay: 0s;
}

.copilot-dialog {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    pointer-events: auto;
    border: 1px solid color-mix(in srgb, var(--border-strong) 70%, transparent);
    border-radius: calc(var(--r-xl) + 4px);
    background: var(--surface-solid);
    box-shadow: 0 24px 70px color-mix(in srgb, #000 28%, transparent), var(--shadow-lg);
    opacity: 0;
    transform: translateY(14px) scale(0.97);
    transform-origin: bottom right;
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.copilot-shell.is-open .copilot-dialog {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.copilot-companion {
    position: absolute;
    right: calc(100% + var(--space-3));
    bottom: 0;
    display: grid;
    align-content: end;
    gap: var(--space-3);
    width: min(360px, calc(100vw - var(--copilot-bubble-width) - 64px));
    max-height: 100%;
    overflow: auto;
    pointer-events: auto;
}

.copilot-companion:empty {
    display: none;
}

.copilot-companion > * {
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    background: var(--surface-solid);
    box-shadow: var(--shadow-lg);
}

.copilot-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-5);
    border-bottom: 1px solid var(--border);
}

.copilot-eyebrow {
    margin-bottom: 2px;
    color: var(--accent-strong);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.copilot-header h2 {
    font-size: 17px;
    line-height: 1.3;
}

.copilot-public-id-search {
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--border-soft);
    background: var(--surface-solid);
}

.public-id-open--compact {
    display: grid;
    gap: 4px;
}

.public-id-open--compact > label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.public-id-open--compact .public-id-open-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-2);
}

.public-id-open--compact input {
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface-2);
    color: var(--text-1);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.public-id-open--compact button {
    min-height: 36px;
    padding: 6px 10px;
}

.public-id-open--compact .public-id-open-status {
    min-height: 0;
    margin: 0;
    color: var(--text-3);
    font-size: 11px;
}

.public-id-open--compact .public-id-open-status:empty {
    display: none;
}

.public-id-open--compact .public-id-open-status.is-error {
    color: var(--warning);
}

.copilot-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface-2);
    color: var(--text-2);
    cursor: pointer;
}

.copilot-icon-button:hover {
    border-color: var(--border-strong);
    background: var(--surface-3);
    color: var(--text-1);
}

.copilot-threads {
    min-height: 48px;
    padding: var(--space-2) var(--space-4);
    overflow-x: auto;
    border-bottom: 1px solid var(--border-soft);
    background: var(--surface-2);
}

.copilot-thread-navigation:empty::before {
    content: "Noch keine Unterhaltung";
    color: var(--text-3);
    font-size: 12px;
}

.copilot-thread-navigation {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: max-content;
}

.copilot-thread,
.copilot-thread-new,
.copilot-history-more {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-solid);
    color: var(--text-2);
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
}

.copilot-thread:hover,
.copilot-thread-new:hover,
.copilot-history-more:hover,
.copilot-thread.is-active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--text-1);
}

.copilot-thread.is-active {
    font-weight: 700;
}

.copilot-transcript {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    padding: var(--space-5);
}

.copilot-message {
    display: grid;
    gap: 3px;
    max-width: 88%;
    margin-bottom: var(--space-4);
}

.copilot-message--user {
    margin-left: auto;
}

.copilot-message-role {
    color: var(--text-3);
    font-size: 10px;
    font-weight: 750;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.copilot-message--user .copilot-message-role {
    text-align: right;
}

.copilot-message-content {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--text-1);
    overflow-wrap: anywhere;
}

.copilot-message-content > :first-child { margin-top: 0; }
.copilot-message-content > :last-child { margin-bottom: 0; }
.copilot-message-content p { margin: 0.55em 0; white-space: pre-wrap; }
.copilot-message-content h1,
.copilot-message-content h2,
.copilot-message-content h3 { margin: 0.8em 0 0.35em; line-height: 1.25; }
.copilot-message-content h1 { font-size: 1.2em; }
.copilot-message-content h2 { font-size: 1.1em; }
.copilot-message-content h3 { font-size: 1em; }
.copilot-message-content ul,
.copilot-message-content ol { margin: 0.55em 0; padding-left: 1.35em; }
.copilot-message-content li + li { margin-top: 0.25em; }
.copilot-message-content code { padding: 0.1em 0.3em; border-radius: 4px; background: var(--surface-3); font-size: 0.9em; }
.copilot-message-content pre { margin: 0.65em 0; padding: 0.7em; overflow-x: auto; border-radius: var(--r-sm); background: var(--surface-3); }
.copilot-message-content pre code { padding: 0; background: transparent; }
.copilot-message-content blockquote { margin: 0.6em 0; padding-left: 0.7em; border-left: 3px solid var(--accent); color: var(--text-2); }
.copilot-message-content a { color: var(--accent-strong); text-decoration: underline; }

.copilot-entity-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-soft);
}

.copilot-message-content .copilot-entity-action {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border));
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.copilot-message-usage {
    margin: 1px 2px 0;
    color: var(--text-3);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.copilot-message-options {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.copilot-message-option {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
    border-radius: var(--r-sm);
    background: var(--accent-soft);
    color: var(--text-1);
    text-align: left;
    cursor: pointer;
}

.copilot-message-option:hover,
.copilot-message-option:focus-visible {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent-soft) 75%, var(--surface-2));
}

.copilot-message--user .copilot-message-content {
    border-color: color-mix(in srgb, var(--accent) 22%, var(--border));
    background: var(--accent-soft);
}

.copilot-message.is-optimistic {
    opacity: 0.72;
}

.copilot-message.is-streaming .copilot-message-content::after {
    content: "";
    display: inline-block;
    width: 6px;
    height: 1em;
    margin-left: 3px;
    vertical-align: text-bottom;
    background: var(--accent);
    animation: copilot-caret 900ms steps(1, end) infinite;
}

@keyframes copilot-caret {
    50% { opacity: 0; }
}

/* Aktivitätsansicht: welche Kontextquellen der Copilot gelesen hat */
.copilot-activity {
    margin: var(--space-2) 0;
    padding: 8px 10px;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    background: color-mix(in srgb, var(--surface-2) 60%, transparent);
}

.copilot-activity-steps {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.copilot-activity-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-2);
}

.copilot-activity-dot {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-4);
}

.copilot-activity-step.is-started .copilot-activity-dot {
    background: var(--accent);
    animation: copilot-activity-pulse 1200ms ease-in-out infinite;
}

.copilot-activity-step.is-completed .copilot-activity-dot {
    background: var(--success);
}

.copilot-activity-step.is-failed .copilot-activity-dot {
    background: var(--danger);
}

.copilot-activity-step.is-failed .copilot-activity-label {
    color: var(--danger);
}

.copilot-activity-label {
    overflow-wrap: anywhere;
}

.copilot-activity-meta {
    margin-left: auto;
    flex: 0 0 auto;
    color: var(--text-4);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.copilot-activity-args {
    display: block;
    margin-left: 15px;
    color: var(--text-3);
    font-size: 11px;
    overflow-wrap: anywhere;
}

@keyframes copilot-activity-pulse {
    50% { opacity: 0.35; }
}

/* Welcher Scope beantwortet wurde: Typ und Public ID, keine Inhalte */
.copilot-scope-chip {
    display: inline-block;
    max-width: 100%;
    margin: 0;
    padding: 2px 8px;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent-soft) 45%, transparent);
    color: var(--text-2);
    font-size: 11px;
    overflow-wrap: anywhere;
}

.copilot-scope-chip:not(:last-child) {
    margin-bottom: 6px;
}

.copilot-reasoning {
    margin-top: 8px;
    border-top: 1px solid var(--border-soft);
    padding-top: 6px;
}

.copilot-reasoning-summary {
    cursor: pointer;
    color: var(--text-3);
    font-size: 12px;
}

.copilot-reasoning-text {
    margin: 6px 0 0;
    color: var(--text-2);
    font-size: 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.copilot-run-status {
    margin: var(--space-2) 0;
    color: var(--text-3);
    font-size: 12px;
}

.copilot-run-status[role="alert"] {
    color: var(--danger);
}

.copilot-history-more {
    display: block;
    margin: 0 auto var(--space-4);
}

.copilot-empty-state {
    max-width: 30ch;
    margin: min(18vh, 120px) auto 0;
    color: var(--text-3);
    text-align: center;
}

.copilot-empty-title {
    margin-bottom: var(--space-2);
    color: var(--text-1);
    font-weight: 700;
}

.copilot-composer-slot {
    min-height: calc(72px + env(safe-area-inset-bottom, 0px));
    padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: var(--surface-solid);
}

.copilot-composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: var(--space-2);
}

.copilot-composer-input {
    width: 100%;
    min-height: 44px;
    max-height: 144px;
    resize: vertical;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    background: var(--surface-2);
    color: var(--text-1);
    line-height: 1.45;
}

.copilot-composer-actions {
    display: flex;
    gap: var(--space-2);
}

.copilot-send,
.copilot-stop,
.copilot-retry {
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    padding: 8px 12px;
    font-weight: 700;
    cursor: pointer;
}

.copilot-send {
    background: var(--accent);
    color: #111;
}

.copilot-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.copilot-stop,
.copilot-retry {
    border-color: var(--border);
    background: var(--surface-2);
    color: var(--text-1);
}

.copilot-error-actions:empty,
.copilot-error-actions:has(> [hidden]) {
    display: none;
}

.copilot-error-actions {
    margin-top: var(--space-2);
    text-align: right;
}

.copilot-live-status {
    position: fixed;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.copilot-launcher {
    position: fixed;
    z-index: 80;
    right: max(20px, env(safe-area-inset-right, 0px));
    bottom: max(20px, env(safe-area-inset-bottom, 0px));
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid color-mix(in srgb, var(--accent) 65%, transparent);
    border-radius: 999px;
    background: var(--accent);
    color: #111;
    box-shadow: var(--shadow-lg);
    font-weight: 750;
    cursor: pointer;
    transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.copilot-launcher:hover {
    background: var(--accent-strong);
    transform: translateY(-1px);
}

.copilot-shell.is-open + .copilot-launcher {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 980px) {
    .copilot-shell,
    .copilot-shell.is-open {
        inset: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        background: color-mix(in srgb, var(--bg) 32%, transparent);
        backdrop-filter: blur(8px);
        opacity: 0;
        pointer-events: none;
        visibility: hidden;
        transition: opacity var(--dur) var(--ease), visibility 0s linear var(--dur);
    }

    .copilot-shell.is-open {
        opacity: 1;
        pointer-events: auto;
        visibility: visible;
        transition-delay: 0s;
    }

    .copilot-shell,
    .copilot-shell.is-open {
        top: var(--copilot-viewport-top, 0);
        bottom: auto;
        height: var(--copilot-viewport-height, 100dvh);
    }

    .copilot-dialog {
        inset: auto 0 0;
        width: 100%;
        height: min(720px, calc(var(--copilot-viewport-height, 100dvh) - max(12px, env(safe-area-inset-top, 0px))));
        max-height: none;
        border-width: 1px 0 0;
        border-radius: var(--r-xl) var(--r-xl) 0 0;
        box-shadow: var(--shadow-lg);
        transform: translateY(24px) scale(1);
        transform-origin: bottom center;
    }

    .copilot-shell.is-open .copilot-dialog {
        transform: translateY(0) scale(1);
    }

    .copilot-companion {
        display: none;
    }

    .copilot-launcher {
        right: max(14px, env(safe-area-inset-right, 0px));
        bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 480px) {
    .copilot-header {
        padding: var(--space-3) var(--space-4);
    }

    .copilot-transcript {
        padding: var(--space-4);
    }

    .copilot-composer {
        grid-template-columns: minmax(0, 1fr);
    }

    .copilot-composer-actions {
        justify-content: flex-end;
    }

    .copilot-send,
    .copilot-stop,
    .copilot-retry {
        min-width: 72px;
        min-height: 44px;
    }

    .copilot-launcher span:last-child {
        display: none;
    }

    .copilot-launcher {
        width: 48px;
        min-height: 48px;
        justify-content: center;
        padding: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .copilot-shell,
    .copilot-dialog,
    .copilot-launcher {
        transition: none;
    }

    .copilot-message.is-streaming .copilot-message-content::after,
    .copilot-activity-step.is-started .copilot-activity-dot {
        animation: none;
    }
}
