/* Spør Roundigo. Farger og avstander kommer fra tokens.css. */

.ai-assistant {
    --ai-bottom: var(--space-4);
    --ai-fab-size: calc(var(--space-12) + var(--space-2));
    --ai-panel-gap: var(--space-3);
}

.ai-fab {
    position: fixed;
    right: max(var(--space-4), env(safe-area-inset-right));
    bottom: var(--ai-bottom);
    z-index: calc(var(--z-modal) + 1);
    width: var(--ai-fab-size);
    height: var(--ai-fab-size);
    padding: 0;
    display: grid;
    place-items: center;
    background: var(--surface);
    color: var(--brand-700);
    border: 2px solid var(--brand-600);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-md);
    cursor: pointer;
}

.ai-fab:hover {
    background: var(--brand-50);
}

.ai-fab:focus-visible {
    outline: none;
    box-shadow: var(--shadow-md), var(--focus-ring);
}

.ai-fab-icon {
    width: 1.7rem;
    height: 1.7rem;
}

.ai-fab-clip {
    width: 2.4rem;
    height: 2.4rem;
    overflow: visible;
}

.ai-clip-wire {
    fill: none;
    stroke: var(--brand-600);
    stroke-width: 2.6;
    stroke-linecap: round;
}

.ai-clip-eye {
    fill: var(--surface);
    stroke: var(--text);
    stroke-width: 0.9;
}

.ai-clip-pupil {
    fill: var(--text);
}

.ai-clip-brow {
    fill: none;
    stroke: var(--text);
    stroke-width: 1.7;
    stroke-linecap: round;
}

.ai-clip-figure {
    animation: ai-clip-bob 4s ease-in-out infinite;
}

.ai-clip-eyes {
    transform-box: fill-box;
    transform-origin: center;
    animation: ai-clip-blink 5.5s infinite;
}

.ai-clip-brows {
    animation: ai-clip-brows 9s ease-in-out infinite;
}

.ai-clip-pupils {
    animation: ai-clip-look 11s ease-in-out infinite;
}

@keyframes ai-clip-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-1.1px); }
}

@keyframes ai-clip-blink {
    0%, 94%, 100% { transform: scaleY(1); }
    97% { transform: scaleY(0.1); }
}

@keyframes ai-clip-brows {
    0%, 16%, 100% { transform: translateY(0); }
    4%, 12% { transform: translateY(-1.4px); }
    8% { transform: translateY(-0.4px); }
}

@keyframes ai-clip-look {
    0%, 52%, 100% { transform: translate(0, 0); }
    60%, 70% { transform: translate(-2.2px, 0); }
    78%, 90% { transform: translate(-1px, -0.4px); }
}

@media (prefers-reduced-motion: reduce) {
    .ai-clip-figure,
    .ai-clip-eyes,
    .ai-clip-brows,
    .ai-clip-pupils {
        animation: none;
    }
}

.ai-panel {
    position: fixed;
    right: max(var(--space-4), env(safe-area-inset-right));
    bottom: calc(var(--ai-viewport-bottom, 0px) + var(--ai-bottom) + var(--ai-fab-size) + var(--ai-panel-gap));
    z-index: calc(var(--z-modal) + 1);
    display: flex;
    flex-direction: column;
    width: min(26rem, calc(100% - var(--space-8)));
    max-height: min(36rem, calc(var(--ai-viewport-height, 100dvh) - var(--ai-bottom) - var(--ai-fab-size) - var(--ai-panel-gap) - var(--header-height) - var(--space-4)));
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.ai-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    flex-shrink: 0;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}

.ai-muted {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.ai-icon-btn {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: var(--control-height);
    height: var(--control-height);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    cursor: pointer;
}

.ai-icon-btn:hover {
    background: var(--surface-hover);
}

.ai-icon-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.ai-messages {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: var(--space-2);
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    overflow-anchor: none;
    padding: var(--space-3) var(--space-4);
}

.ai-messages:focus-visible {
    outline: 2px solid var(--brand-600);
    outline-offset: calc(-1 * var(--space-1));
}

#ai-messages {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: var(--space-3);
}

.ai-welcome {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-2) 0 var(--space-3);
}

.ai-welcome-title {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-snug);
}

.ai-welcome-copy {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
}

.ai-privacy-notice {
    margin: var(--space-3) 0 0;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    line-height: var(--leading-normal);
}

.ai-bubble {
    max-width: 88%;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-button);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    overflow-wrap: anywhere;
}

.ai-message-author {
    display: block;
    margin-bottom: var(--space-1);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
}

.ai-bubble-user .ai-message-text {
    white-space: pre-wrap;
}

.ai-bubble-user {
    justify-self: end;
    background: var(--brand-600);
    color: var(--text-on-brand);
}

.ai-bubble-assistant {
    justify-self: start;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
}

.ai-markdown p {
    margin: 0 0 var(--space-2);
}

.ai-markdown ul,
.ai-markdown ol {
    margin: var(--space-1) 0 var(--space-2);
    padding-left: 1.2rem;
}

.ai-markdown > :first-child {
    margin-top: 0;
}

.ai-markdown > :last-child {
    margin-bottom: 0;
}

.ai-markdown a {
    color: var(--brand-700);
    text-decoration: underline;
}

.ai-markdown pre {
    max-width: 100%;
    overflow-x: auto;
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.ai-markdown table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.ai-starters {
    display: grid;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.ai-starter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    width: 100%;
    min-height: var(--space-12);
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-button);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    text-align: left;
    cursor: pointer;
}

.ai-starter:hover:not(:disabled) {
    background: var(--brand-50);
    border-color: var(--brand-200);
}

.ai-starter:disabled {
    opacity: 0.6;
    cursor: default;
}

.ai-starter:focus-visible,
.ai-send:focus-visible,
.ai-retry:focus-visible,
.ai-about summary:focus-visible,
.ai-composer textarea:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.ai-error {
    margin: 0;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-sm);
    background: var(--danger-bg);
    color: var(--danger-text);
    font-size: var(--text-sm);
}

.ai-retry {
    justify-self: start;
    min-height: var(--control-height);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-button);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    cursor: pointer;
}

.ai-retry:hover:not(:disabled) {
    background: var(--surface-hover);
}

.ai-retry:disabled {
    opacity: 0.6;
    cursor: default;
}

.ai-about {
    flex-shrink: 1;
    min-height: var(--control-height-sm);
    overflow-y: auto;
    padding: 0 var(--space-4);
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    line-height: var(--leading-normal);
}

.ai-about summary {
    width: fit-content;
    min-height: var(--control-height-sm);
    padding: var(--space-2) 0;
    border-radius: var(--radius-xs);
    cursor: pointer;
}

.ai-about-copy {
    max-height: min(10rem, calc(var(--ai-viewport-height, 100dvh) * 0.35 - var(--space-10)));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: var(--space-3);
}

.ai-about-copy p {
    margin: 0 0 var(--space-2);
}

.ai-about-copy > :last-child {
    margin-bottom: 0;
}

.ai-composer {
    display: flex;
    align-items: end;
    flex-shrink: 0;
    gap: var(--space-2);
    padding: var(--space-3);
    border-top: 1px solid var(--border);
}

.ai-composer textarea {
    flex: 1 1 auto;
    min-width: 0;
    min-height: var(--control-height);
    max-height: calc(var(--text-base) * var(--leading-snug) * 4 + var(--space-5));
    box-sizing: border-box;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-button);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: var(--text-base);
    line-height: var(--leading-snug);
    resize: none;
}

.ai-send {
    flex-shrink: 0;
    min-height: var(--control-height);
    padding: 0 var(--space-4);
    border: 0;
    border-radius: var(--radius-button);
    background: var(--brand-600);
    color: var(--text-on-brand);
    font: inherit;
    font-weight: var(--weight-semibold);
    cursor: pointer;
}

.ai-send:hover:not(:disabled) {
    background: var(--brand-700);
}

.ai-send:disabled {
    opacity: 0.55;
    cursor: default;
}

.ai-status {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-button);
    font-size: var(--text-sm);
}

.ai-status--ok {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

.ai-status--off {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning-text);
}

.ai-test-reply {
    margin-top: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-sunken);
    white-space: pre-wrap;
}

.ai-test-context {
    max-height: 20rem;
    overflow: auto;
    margin-top: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    white-space: pre-wrap;
}

.ai-entry {
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
}

.ai-entry-body {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.ai-log-counts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
}

.ai-log-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-3);
    align-items: center;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.ai-log-status {
    padding: 0.05rem var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface);
    font-size: var(--text-xs);
}

.ai-log-status--noanswer {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning-text);
}

.ai-log-status--unavailable {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger-text);
}

.ai-log-q {
    font-weight: var(--weight-medium);
    overflow-wrap: anywhere;
}

.ai-log-a {
    color: var(--text-secondary);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

@media (max-width: 1024px) {
    .ai-assistant {
        --ai-bottom: calc(var(--space-16) + var(--space-3) + env(safe-area-inset-bottom, 0px));
    }
}

/* Use the visible viewport when a keyboard or landscape screen leaves little room. */
.ai-panel[data-ai-compact="true"] {
    bottom: calc(var(--ai-viewport-bottom, 0px) + var(--space-2));
    max-height: calc(var(--ai-viewport-height, 100dvh) - var(--space-4));
}

.ai-assistant:has(.ai-panel[data-ai-compact="true"]) .ai-fab {
    visibility: hidden;
}

@media (max-height: 540px) {
    .ai-panel {
        bottom: calc(var(--ai-viewport-bottom, 0px) + var(--space-2));
        max-height: calc(var(--ai-viewport-height, 100dvh) - var(--space-4));
    }

    .ai-assistant:has(.ai-panel) .ai-fab {
        visibility: hidden;
    }
}

@media (max-width: 480px) {
    .ai-panel {
        right: max(var(--space-2), env(safe-area-inset-right));
        width: calc(100% - var(--space-4));
    }
}
