/*
 * Jobbs AI — hjälpchatten i admin (Shared/AiHelp/AiAssistant.razor + jobbs/js/ai-assistant.js).
 *
 * Global fil, inte scopad CSS: svaret renderas av JS och mörkt läge sätts på <html data-bs-theme>.
 * Allt ligger under .ai-assist. Blazor styr data-open/data-busy på roten; klasserna (is-expanded,
 * is-mac, has-input, is-scrolled-up, has-news) sätts av JS.
 */

@property --ai-angle {
    syntax: "<angle>";
    initial-value: 0deg;
    inherits: true;
}

/* ── Tokens ──────────────────────────────────────────────────────────────── */

.ai-assist {
    --ai-violet: #6d27ff;
    --ai-violet-2: #8b5cf6;
    --ai-violet-3: #b69cff;
    --ai-grad: linear-gradient(135deg, #9466ff 0%, #6d27ff 48%, #4f46e5 100%);
    --ai-spectrum: conic-gradient(from var(--ai-angle),
        #6d27ff, #a855f7 16%, #ec4899 32%, #f59e0b 44%, #38bdf8 62%, #6366f1 80%, #6d27ff);

    --ai-surface: rgba(255, 255, 255, .95);
    --ai-surface-solid: #ffffff;
    --ai-elev: #f7f6fb;
    --ai-elev-2: #efedf6;
    --ai-tint: rgba(109, 39, 255, .06);
    --ai-tint-2: rgba(109, 39, 255, .1);
    --ai-border: rgba(24, 16, 64, .08);
    --ai-border-2: rgba(24, 16, 64, .13);
    --ai-border-accent: rgba(109, 39, 255, .38);
    /* Kontrast mot panelen (WCAG): text 18.5:1, text-2 14:1, icon 7.8:1, muted 6:1.
       faint (2.6:1) är bara för ren dekor — aldrig för text eller en kontroll man ska se. */
    --ai-text: #121022;
    --ai-text-2: #2b283f;
    --ai-icon: #524f68;
    --ai-muted: #63607a;
    --ai-faint: #a19eb6;
    --ai-danger: #d92d45;
    --ai-danger-bg: rgba(217, 45, 69, .07);
    --ai-user-bg: #f1edff;
    --ai-user-border: rgba(109, 39, 255, .1);

    --ai-shadow:
        0 0 0 1px rgba(24, 16, 64, .07),
        0 2px 4px rgba(24, 16, 64, .04),
        0 24px 56px -20px rgba(24, 16, 64, .28),
        0 48px 100px -48px rgba(40, 14, 110, .24);

    --ai-ease: cubic-bezier(.22, .8, .26, 1);
    --ai-spring: cubic-bezier(.2, .9, .22, 1.08);
    --ai-radius: 24px;   /* panelen */
    --ai-r-lg: 16px;     /* inmatning, bubbla */
    --ai-r-md: 12px;     /* kort, fel, knappar */
    --ai-r-sm: 8px;      /* ikonknappar, bricka */

    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1045; /* under Bootstrap- och Telerik-modaler, över sidans innehåll */
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-feature-settings: "cv11", "ss01";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--ai-text);
}

[data-bs-theme="dark"] .ai-assist {
    --ai-surface: rgba(18, 16, 28, .88);
    --ai-surface-solid: #15131f;
    --ai-elev: #1c1929;
    --ai-elev-2: #242034;
    --ai-tint: rgba(167, 139, 250, .08);
    --ai-tint-2: rgba(167, 139, 250, .14);
    --ai-border: rgba(255, 255, 255, .07);
    --ai-border-2: rgba(255, 255, 255, .12);
    --ai-border-accent: rgba(167, 139, 250, .5);
    --ai-text: #f1f0f8;
    --ai-text-2: #dcdae8;
    --ai-icon: #c0bcd4;
    --ai-muted: #a9a5c0;
    --ai-faint: #76728f;
    --ai-danger: #ff6b81;
    --ai-danger-bg: rgba(255, 107, 129, .1);
    --ai-user-bg: rgba(139, 92, 246, .14);
    --ai-user-border: rgba(167, 139, 250, .16);
    --ai-shadow:
        0 0 0 1px rgba(255, 255, 255, .07),
        0 24px 64px -16px rgba(0, 0, 0, .7),
        0 0 90px -40px rgba(109, 39, 255, .3);
}

/* Metronics "till toppen"-knapp ligger också nere till höger — lyft den ovanför. */
body:has(.ai-assist) #kt_scrolltop {
    bottom: 96px;
    right: 35px;
}

.ai-assist *,
.ai-assist *::before,
.ai-assist *::after {
    box-sizing: border-box;
}

.ai-assist button { font-family: inherit; }
.ai-assist [hidden] { display: none !important; }

.ai-assist kbd {
    display: inline-block;
    padding: 0 5px;
    border-radius: 4px;
    border: 1px solid var(--ai-border-2);
    border-bottom-width: 2px;
    background: var(--ai-surface-solid);
    color: var(--ai-muted);
    font: 600 10px/1.6 Inter, sans-serif;
    letter-spacing: .02em;
}

.ai-assist .ai-key-mac { display: none; }
.ai-assist.is-mac .ai-key-other { display: none; }
.ai-assist.is-mac .ai-key-mac { display: inline-block; }

/* ── Orben ───────────────────────────────────────────────────────────────── */

.ai-orb {
    position: relative;
    flex-shrink: 0;
    border-radius: 50%;
    isolation: isolate;
    overflow: hidden;
    background: #5b21f5;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22);
}

.ai-orb > span {
    position: absolute;
    inset: -40%;
    background:
        radial-gradient(circle at 30% 30%, #f0abfc 0 12%, transparent 40%),
        radial-gradient(circle at 72% 70%, #38bdf8 0 8%, transparent 42%),
        radial-gradient(circle at 70% 25%, #6366f1 0 10%, transparent 45%),
        conic-gradient(from 0deg, #6d27ff, #a855f7, #ec4899, #6366f1, #6d27ff);
    filter: blur(6px) saturate(115%);
    animation: ai-rotate 20s linear infinite;
}

/* Glanspunkt, som på en glaskula. */
.ai-orb > i {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background:
        radial-gradient(circle at 32% 24%, rgba(255, 255, 255, .85) 0, rgba(255, 255, 255, 0) 32%),
        radial-gradient(circle at 50% 120%, rgba(56, 189, 248, .35), transparent 55%);
}

.ai-orb.xs { width: 26px; height: 26px; }
.ai-orb.xs > span { filter: blur(3px) saturate(125%); }
.ai-orb.sm { width: 32px; height: 32px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22), 0 4px 12px -6px rgba(109, 39, 255, .45); }
.ai-orb.lg {
    width: 64px;
    height: 64px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25), 0 16px 36px -16px rgba(109, 39, 255, .5);
    animation: ai-float 9s ease-in-out infinite;
}
.ai-orb.lg > span { filter: blur(8px) saturate(115%); animation-duration: 28s; }

/* Arbetar: orben snurrar fortare — men lugnt; kanten runt panelen bär redan signalen. */
.ai-assist[data-busy="true"] .ai-orb.sm > span,
.ai-msg-assistant.is-live .ai-orb.xs > span { animation-duration: 5s; }

.ai-msg-assistant.is-live .ai-orb.xs { animation: ai-pulse-ring 2.4s ease-out infinite; }

/* ── Knappen ─────────────────────────────────────────────────────────────── */

.ai-launcher {
    position: relative;
    display: block;
    height: 58px;
    margin-left: auto;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform .4s var(--ai-spring), opacity .25s ease;
}

.ai-launcher:active { transform: scale(.96); }

/* Spektrumringen: långsam i vila, snabbare när den arbetar med panelen stängd, borta när
   panelen är öppen — då bär panelen själv uppmärksamheten. */
.ai-launcher-glow {
    position: absolute;
    inset: -2px;
    border-radius: 999px;
    background: var(--ai-spectrum);
    opacity: .9;
    animation: ai-spin 12s linear infinite;
    transition: opacity .4s ease;
}

.ai-launcher-glow::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: inherit;
    background: inherit;
    filter: blur(14px);
    opacity: .2;
    animation: ai-breathe 7s ease-in-out infinite;
}

.ai-assist[data-open="true"] .ai-launcher-glow {
    opacity: 0;
    animation-play-state: paused;
}

.ai-assist[data-open="true"] .ai-launcher-glow::after { animation: none; }

.ai-launcher-body {
    position: relative;
    display: flex;
    align-items: center;
    height: 58px;
    min-width: 58px;
    border-radius: 999px;
    background: var(--ai-grad);
    color: #fff;
    overflow: hidden;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .35),
        inset 0 -10px 20px rgba(38, 8, 120, .3),
        0 10px 24px -10px rgba(109, 39, 255, .55);
    transition: box-shadow .3s ease;
}

.ai-assist[data-open="true"] .ai-launcher-body {
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .3),
        inset 0 -10px 20px rgba(38, 8, 120, .25),
        0 6px 16px -8px rgba(40, 14, 110, .45);
}

/* Ljusreflexen som sveper över. */
.ai-launcher-body::before {
    content: "";
    position: absolute;
    top: -60%;
    left: -140%;
    width: 70%;
    height: 220%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .35), transparent);
    transform: rotate(18deg);
    animation: ai-sweep 14s var(--ai-ease) infinite;
}

.ai-assist[data-open="true"] .ai-launcher-body::before { animation: none; }

.ai-launcher-icons {
    position: relative;
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    flex-shrink: 0;
}

.ai-launcher-icons > span {
    grid-area: 1 / 1;
    display: grid;
    place-items: center;
    transition: opacity .25s ease, transform .5s var(--ai-spring);
}

.ai-launcher-spark svg { width: 26px; height: 26px; filter: drop-shadow(0 1px 2px rgba(30, 0, 90, .4)); }
.ai-launcher-close { font-size: 22px; opacity: 0; transform: rotate(-90deg) scale(.5); }

.ai-assist[data-open="true"] .ai-launcher-spark { opacity: 0; transform: rotate(90deg) scale(.5); }
.ai-assist[data-open="true"] .ai-launcher-close { opacity: 1; transform: none; }

/* Knappen växer till en pill med text när man för musen över den. */
.ai-launcher-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -.005em;
    transition: max-width .45s var(--ai-ease), opacity .25s ease, padding .45s var(--ai-ease);
}

.ai-launcher-label kbd {
    border-color: rgba(255, 255, 255, .3);
    background: rgba(255, 255, 255, .16);
    color: #fff;
}

.ai-assist[data-open="false"] .ai-launcher:hover .ai-launcher-label,
.ai-assist[data-open="false"] .ai-launcher:focus-visible .ai-launcher-label {
    max-width: 220px;
    opacity: 1;
    padding-right: 20px;
    transition-delay: .08s, .12s, .08s;
}

.ai-launcher:focus-visible { outline: none; }
.ai-launcher:focus-visible .ai-launcher-body { box-shadow: 0 0 0 4px rgba(109, 39, 255, .3), inset 0 1px 0 rgba(255, 255, 255, .4); }

.ai-assist[data-busy="true"] .ai-launcher-glow { animation-duration: 3s; }

.ai-launcher-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #22c55e;
    border: 2.5px solid var(--ai-surface-solid);
    animation: ai-pop .4s var(--ai-spring);
}

.ai-assist.is-expanded[data-open="true"] .ai-launcher {
    opacity: 0;
    pointer-events: none;
    transform: scale(.8);
}

/* ── Ramen och glöden ────────────────────────────────────────────────────── */

.ai-frame {
    position: fixed;
    right: 24px;
    bottom: 96px;
    width: min(440px, calc(100vw - 32px));
    height: min(720px, calc(100vh - 120px));
    transform-origin: calc(100% - 29px) calc(100% + 43px);
    opacity: 0;
    transform: translateY(18px) scale(.9);
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity .2s ease,
        transform .42s var(--ai-spring),
        width .5s var(--ai-ease),
        height .5s var(--ai-ease),
        bottom .5s var(--ai-ease),
        right .5s var(--ai-ease),
        visibility 0s linear .42s;
}

.ai-assist[data-open="true"] .ai-frame {
    opacity: 1;
    transform: none;
    visibility: visible;
    pointer-events: auto;
    transition:
        opacity .22s ease,
        transform .55s var(--ai-spring),
        width .5s var(--ai-ease),
        height .5s var(--ai-ease),
        bottom .5s var(--ai-ease),
        right .5s var(--ai-ease),
        visibility 0s;
}

/* Utfällt: en sidopanel i full höjd. */
.ai-assist.is-expanded .ai-frame {
    right: 16px;
    bottom: 16px;
    width: min(760px, calc(100vw - 32px));
    height: calc(100vh - 32px);
    transform-origin: 100% 100%;
}

/* Kanten som lyser medan assistenten arbetar — samma idé som Apple Intelligence. */
.ai-glow {
    position: absolute;
    inset: 0;
    border-radius: var(--ai-radius);
    pointer-events: none;
    opacity: 0;
    transition: opacity .7s ease;
}

.ai-assist[data-busy="true"] .ai-glow { opacity: 1; }

.ai-glow-bloom,
.ai-glow-rim {
    position: absolute;
    border-radius: inherit;
    background: var(--ai-spectrum);
    animation: ai-spin 4.5s linear infinite;
}

/* Tydlig medan assistenten arbetar — det är den som visar att något händer. */
.ai-glow-bloom {
    inset: -5px;
    filter: blur(20px);
    opacity: .4;
    z-index: -1;
}

.ai-glow-rim {
    inset: -1.5px;
    border-radius: calc(var(--ai-radius) + 1.5px);
    padding: 1.5px;
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 1;
    z-index: 4;
}

/* ── Panelen ─────────────────────────────────────────────────────────────── */

.ai-panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    border-radius: var(--ai-radius);
    background: var(--ai-surface);
    -webkit-backdrop-filter: blur(32px) saturate(180%);
    backdrop-filter: blur(32px) saturate(180%);
    box-shadow: var(--ai-shadow);
    overflow: hidden;
}

/* En svag aurora längst upp i panelen. */
.ai-panel::before {
    content: "";
    position: absolute;
    left: -20%;
    right: -20%;
    top: -140px;
    height: 280px;
    background:
        radial-gradient(40% 50% at 25% 50%, rgba(139, 92, 246, .12), transparent 70%),
        radial-gradient(35% 45% at 75% 40%, rgba(236, 72, 153, .06), transparent 70%),
        radial-gradient(30% 40% at 55% 60%, rgba(56, 189, 248, .06), transparent 70%);
    filter: blur(12px);
    animation: ai-drift 40s ease-in-out infinite alternate;
    pointer-events: none;
}

.ai-panel > * { position: relative; }
.ai-panel > .ai-jump,
.ai-panel > .ai-toast { position: absolute; }

/* ── Rubrikraden ─────────────────────────────────────────────────────────── */

.ai-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 12px 12px 20px;
    flex-shrink: 0;
    z-index: 2;
}

.ai-heading {
    flex: 1;
    min-width: 0;
}

.ai-heading h2 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    line-height: 20px;
    letter-spacing: -.012em;
    color: var(--ai-text);
}

/* Neutralt märke — en upplysning, inte en accent. */
.ai-heading h2::after {
    content: "Beta";
    padding: 0 6px;
    border-radius: 6px;
    box-shadow: inset 0 0 0 1px var(--ai-border-2);
    color: var(--ai-muted);
    font-size: 11px;
    font-weight: 500;
    line-height: 18px;
    letter-spacing: 0;
}

.ai-heading p {
    margin: 0;
    font-size: 12.5px;
    line-height: 18px;
    color: var(--ai-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.ai-icon-btn {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: var(--ai-r-sm);
    background: transparent;
    color: var(--ai-icon);
    font-size: 18px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, transform .25s var(--ai-spring);
}

.ai-icon-btn:hover:not(:disabled) { background: var(--ai-elev-2); color: var(--ai-text); }
.ai-icon-btn:active:not(:disabled) { transform: scale(.9); }
.ai-icon-btn:disabled { opacity: .35; cursor: default; }
.ai-icon-btn:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 1px; }
[data-bs-theme="dark"] .ai-icon-btn:focus-visible { outline-color: var(--ai-violet-3); }
.ai-icon-btn.sm { width: 28px; height: 28px; border-radius: var(--ai-r-sm); font-size: 16px; }
.ai-icon-btn.is-active { color: var(--ai-violet); }
[data-bs-theme="dark"] .ai-icon-btn.is-active { color: var(--ai-violet-3); }

/* ── Samtalet ────────────────────────────────────────────────────────────── */

.ai-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px 20px 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--ai-border-2) transparent;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 12px), transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 12px), transparent 100%);
}

.ai-assist.is-expanded .ai-body { padding: 8px max(28px, calc((100% - 620px) / 2)) 12px; }

/* Välkomstläget. */
.ai-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 32px 4px 8px;
}

.ai-hero .ai-orb { margin-bottom: 20px; }

/* Hälsningen: en stilla gradient — den skimrade förut, men stod då och tävlade med orben. */
.ai-hero-kicker {
    margin: 0 0 4px;
    font-size: 13px;
    font-weight: 500;
    background: linear-gradient(90deg, #6d27ff, #a21caf);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

[data-bs-theme="dark"] .ai-hero-kicker {
    background-image: linear-gradient(90deg, #b69cff, #e9a8f5);
}

.ai-hero h3 {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -.02em;
    color: var(--ai-text);
    text-wrap: balance;
}

.ai-hero-lead {
    margin: 0 0 24px;
    max-width: 320px;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--ai-muted);
    text-wrap: pretty;
}

.ai-cards {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.ai-assist.is-expanded .ai-cards { grid-template-columns: 1fr 1fr; }

.ai-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px 12px 12px;
    border: 1px solid var(--ai-border-2);
    border-radius: var(--ai-r-md);
    background: var(--ai-surface-solid);
    color: var(--ai-text);
    font-size: 13.5px;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(24, 16, 64, .04);
    animation: ai-rise .5s var(--ai-ease) both;
    animation-delay: calc(var(--i, 0) * 50ms + 60ms);
    transition: border-color .2s ease, background .2s ease, box-shadow .25s ease;
}

.ai-card-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: var(--ai-r-sm);
    background: var(--ai-tint);
    color: var(--ai-violet);
    font-size: 18px;
    transition: background .2s ease;
}

[data-bs-theme="dark"] .ai-card-icon { color: var(--ai-violet-3); }

.ai-card-text { flex: 1; }

.ai-card-go {
    font-size: 14px;
    color: var(--ai-faint); /* dekor — kortets text bär handlingen */
    transition: transform .3s var(--ai-spring), color .2s ease;
}

.ai-card:hover {
    border-color: var(--ai-border-accent);
    box-shadow: 0 6px 16px -10px rgba(40, 14, 110, .3);
}

.ai-card:hover .ai-card-icon { background: var(--ai-tint-2); }
.ai-card:hover .ai-card-go { color: var(--ai-icon); transform: translate(1px, -1px); }
.ai-card:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; }
[data-bs-theme="dark"] .ai-card:focus-visible { outline-color: var(--ai-violet-3); }

/* Utbyten. */
.ai-exchange { padding-top: 16px; }
.ai-exchange + .ai-exchange { margin-top: 8px; }

.ai-msg {
    display: flex;
    gap: 12px;
    animation: ai-rise .42s var(--ai-ease) both;
}

.ai-msg-user {
    justify-content: flex-end;
    margin-bottom: 20px;
}

.ai-bubble {
    max-width: 86%;
    padding: 10px 14px;
    border-radius: var(--ai-r-lg) var(--ai-r-lg) 4px var(--ai-r-lg);
    background: var(--ai-user-bg);
    border: 1px solid var(--ai-user-border);
    color: var(--ai-text);
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Svaret använder hela bredden. Orben står på samma rad som "Tänkte i …" i stället för i en egen
   spalt, som annars flyttar in all text ~36 px. */
.ai-msg-assistant {
    position: relative;
    display: block;
}

.ai-msg-assistant .ai-orb.xs,
.ai-msg-assistant .ai-mark.xs {
    position: absolute;
    top: 0;
    left: 0;
    width: 24px;
    height: 24px;
}
.ai-msg-assistant .ai-mark.xs { top: 1px; width: 22px; height: 22px; }

.ai-content {
    min-width: 0;
    min-height: 24px;
}

.ai-msg-assistant .ai-thought-toggle { margin-left: 24px; min-height: 24px; }
.ai-msg-assistant .ai-steps { padding-left: 2px; }

/* ── Stegen ──────────────────────────────────────────────────────────────── */

.ai-thought { margin: 0 0 8px; }

.ai-thought-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: -8px;
    padding: 2px 8px;
    border: 0;
    border-radius: var(--ai-r-sm);
    background: transparent;
    color: var(--ai-muted);
    font-size: 12.5px;
    font-weight: 500;
    line-height: 20px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.ai-thought-toggle:hover { background: var(--ai-elev-2); color: var(--ai-text); }
.ai-thought-toggle:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 1px; }
[data-bs-theme="dark"] .ai-thought-toggle:focus-visible { outline-color: var(--ai-violet-3); }
.ai-thought-caret { font-size: 11px; transition: transform .35s var(--ai-spring); }
.ai-thought.is-open .ai-thought-caret { transform: rotate(180deg); }
.ai-thought.is-thinking .ai-thought-caret { display: none; }

/* Skimret över det aktiva steget — ett ljusare band som glider, inget regnbågsfält. */
.ai-thought.is-thinking .ai-thought-label {
    background: linear-gradient(90deg,
        var(--ai-muted) 0%, var(--ai-muted) 38%,
        var(--ai-violet-2) 50%,
        var(--ai-muted) 62%, var(--ai-muted) 100%);
    background-size: 280% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: ai-shimmer 2.6s linear infinite;
}

.ai-thought-body {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows .4s var(--ai-ease);
}

.ai-thought.is-open .ai-thought-body,
.ai-thought.is-thinking .ai-thought-body { grid-template-rows: 1fr; }

.ai-steps {
    min-height: 0;
    overflow: hidden;
    list-style: none;
    margin: 0;
    padding: 4px 0 0;
}

.ai-steps li {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
    font-size: 12.5px;
    color: var(--ai-muted);
    animation: ai-rise .32s var(--ai-ease) both;
}

.ai-steps li + li::before {
    content: "";
    position: absolute;
    left: 9.5px;
    top: -4px;
    width: 1px;
    height: 8px;
    background: var(--ai-border-2);
}

.ai-step-dot {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    border-radius: 50%;
    font-size: 11px;
}

/* Klara steg är neutrala — bara det pågående steget får accent. */
.ai-steps li.is-done .ai-step-dot {
    color: var(--ai-icon);
    background: var(--ai-elev-2);
    animation: ai-pop .32s var(--ai-spring);
}

.ai-steps li.is-active { color: var(--ai-text); }

.ai-steps li.is-active .ai-step-dot {
    color: var(--ai-violet);
    background: var(--ai-surface-solid);
    box-shadow: inset 0 0 0 1.5px var(--ai-border-accent);
    animation: ai-pulse-step 2.4s ease-out infinite;
}

[data-bs-theme="dark"] .ai-steps li.is-active .ai-step-dot { color: var(--ai-violet-3); }

/* Skelett medan svaret förbereds. */
.ai-skeleton {
    display: grid;
    gap: 8px;
    padding: 8px 0 4px;
}

.ai-skeleton i {
    display: block;
    height: 10px;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--ai-elev-2) 0%, var(--ai-tint-2) 40%, var(--ai-elev-2) 80%);
    background-size: 240% 100%;
    animation: ai-shimmer 2.2s linear infinite;
}

.ai-skeleton i:nth-child(1) { width: 92%; }
.ai-skeleton i:nth-child(2) { width: 78%; animation-delay: .12s; }
.ai-skeleton i:nth-child(3) { width: 54%; animation-delay: .24s; }

/* ── Svaret ──────────────────────────────────────────────────────────────── */

/* En gråskala: brödtext och fetstil har samma färg, fetstilen skiljer sig bara i vikt. Accenten
   (lila) är förbehållen det man kan klicka på. */
.ai-answer {
    font-size: 14px;
    line-height: 1.65;
    color: var(--ai-text-2);
    overflow-wrap: anywhere;
    text-wrap: pretty;
}

.ai-answer:empty { display: none; }
.ai-answer > :first-child { margin-top: 0; }
.ai-answer > :last-child { margin-bottom: 0; }
.ai-answer p { margin: 0 0 .85em; }

.ai-answer h3, .ai-answer h4 {
    margin: 1.25em 0 .5em;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -.01em;
    color: var(--ai-text);
}

.ai-answer ul, .ai-answer ol { margin: 0 0 .85em; padding-left: 1.5em; }
.ai-answer li { margin: .4em 0; padding-left: .25em; }
.ai-answer li > ul, .ai-answer li > ol { margin: .3em 0 .2em; }
.ai-answer ol > li::marker { color: var(--ai-muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.ai-answer ul > li::marker { color: var(--ai-muted); }

.ai-answer strong { font-weight: 600; color: inherit; }

/* Länken: textfärg med en lila understrykning — syns som länk utan att lysa. Hovring ger färgen. */
.ai-answer a {
    color: var(--ai-text);
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: rgba(109, 39, 255, .5);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: color .15s ease, text-decoration-color .15s ease;
}

.ai-answer a::after {
    content: "\2197";
    display: inline-block;
    margin-left: 2px;
    color: var(--ai-muted);
    font-size: .85em;
    text-decoration: none;
    transition: transform .25s var(--ai-spring), color .15s ease;
}

.ai-answer a:hover { color: var(--ai-violet); text-decoration-color: currentColor; }
.ai-answer a:hover::after { color: currentColor; transform: translate(1px, -1px); }
.ai-answer a:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; border-radius: 2px; }
[data-bs-theme="dark"] .ai-answer a { text-decoration-color: rgba(182, 156, 255, .55); }
[data-bs-theme="dark"] .ai-answer a:hover { color: var(--ai-violet-3); text-decoration-color: currentColor; }
[data-bs-theme="dark"] .ai-answer a:focus-visible { outline-color: var(--ai-violet-3); }

.ai-answer code {
    padding: .1em .4em;
    border-radius: 4px;
    background: var(--ai-elev-2);
    color: var(--ai-text);
    font-size: .88em;
}

.ai-answer blockquote {
    margin: 0 0 .85em;
    padding: 8px 12px;
    border-left: 2px solid var(--ai-border-accent);
    border-radius: 0 var(--ai-r-sm) var(--ai-r-sm) 0;
    background: var(--ai-elev);
    color: var(--ai-text-2);
}

/* Nya ord tonas in från oskärpa — ett i taget, som hos de stora. */
.ai-answer .ai-w {
    animation: ai-word .42s var(--ai-ease) both;
}

/* Markören. */
.ai-answer.is-streaming > :last-child:not(ul):not(ol)::after,
.ai-answer.is-streaming > :is(ul, ol):last-child > li:last-child::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-left: 6px;
    border-radius: 50%;
    background: var(--ai-grad);
    box-shadow: 0 0 8px rgba(109, 39, 255, .35);
    vertical-align: middle;
    animation: ai-caret 1.2s ease-in-out infinite;
}

/* ── Fel, stopp, åtgärder, följdfrågor ───────────────────────────────────── */

.ai-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--ai-r-md);
    background: var(--ai-danger-bg);
    color: var(--ai-danger);
    font-size: 13px;
    line-height: 1.45;
}

.ai-error i { font-size: 17px; flex-shrink: 0; }
.ai-error span { flex: 1; color: var(--ai-text); }

.ai-error button,
.ai-full button {
    padding: 4px 12px;
    border: 0;
    border-radius: var(--ai-r-sm);
    background: var(--ai-surface-solid);
    color: var(--ai-text);
    font-size: 12.5px;
    font-weight: 500;
    line-height: 20px;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--ai-border-2);
}

.ai-error button:hover,
.ai-full button:hover { box-shadow: 0 0 0 1px var(--ai-border-accent); }

.ai-error button:focus-visible,
.ai-full button:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; }

.ai-stopped {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    color: var(--ai-muted);
    font-size: 12px;
}

.ai-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    /* Ikonernas glyf linjerar med textkanten: 28px knapp, 16px ikon → 6px luft. */
    margin: 12px 0 0 -6px;
    animation: ai-rise .35s var(--ai-ease) both;
}

.ai-actions-sep {
    width: 1px;
    height: 16px;
    margin: 0 4px;
    background: var(--ai-border-2);
}

.ai-gap {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    color: var(--ai-muted);
    font-size: 12px;
}

.ai-gap i { font-size: 13px; }

/* ── Ärende till support ─────────────────────────────────────────────────── */

.ai-support-cta {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    margin: 10px 0 0;
    padding: 10px 12px;
    border: 1px solid var(--ai-border-2);
    border-radius: var(--ai-r-md);
    background: var(--ai-surface-solid);
    color: var(--ai-text);
    text-align: left;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
    animation: ai-rise .35s var(--ai-ease) both;
}

.ai-support-cta:hover { border-color: var(--ai-border-accent); background: var(--ai-tint); }
.ai-support-cta:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; }
.ai-support-cta > i:first-child { font-size: 22px; color: var(--ai-violet); flex-shrink: 0; }
.ai-support-cta > i:last-child { font-size: 14px; color: var(--ai-muted); flex-shrink: 0; transition: transform .3s var(--ai-spring); }
.ai-support-cta:hover > i:last-child { transform: translateX(2px); color: var(--ai-violet); }
.ai-support-cta span { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ai-support-cta strong { font-size: 13px; font-weight: 600; line-height: 18px; }
.ai-support-cta small { font-size: 12px; color: var(--ai-muted); line-height: 17px; }
[data-bs-theme="dark"] .ai-support-cta > i:first-child,
[data-bs-theme="dark"] .ai-support-cta:hover > i:last-child { color: var(--ai-violet-3); }

.ai-support {
    margin: 16px 0 4px;
    padding: 12px 14px 14px;
    border: 1px solid var(--ai-border-2);
    border-radius: var(--ai-r-lg);
    background: var(--ai-surface-solid);
    box-shadow: 0 1px 2px rgba(24, 16, 64, .04);
    animation: ai-rise .35s var(--ai-ease) both;
}

.ai-support-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 13.5px;
}

.ai-support-head > i { font-size: 20px; color: var(--ai-violet); }
.ai-support-head strong { flex: 1; font-weight: 600; color: var(--ai-text); }
.ai-support-head .ai-icon-btn { margin-right: -6px; }
[data-bs-theme="dark"] .ai-support-head > i { color: var(--ai-violet-3); }

.ai-support-label {
    display: block;
    margin-bottom: 6px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--ai-text-2);
}

.ai-support textarea {
    display: block;
    width: 100%;
    min-height: 96px;
    padding: 9px 11px;
    border: 1px solid var(--ai-border-2);
    border-radius: var(--ai-r-md);
    background: var(--ai-elev);
    color: var(--ai-text);
    font: inherit;
    font-size: 13.5px;
    line-height: 20px;
    resize: vertical;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.ai-support textarea:focus { border-color: var(--ai-border-accent); box-shadow: 0 0 0 3px var(--ai-tint-2); }

.ai-support-note {
    margin: 8px 0 0;
    font-size: 12px;
    line-height: 17px;
    color: var(--ai-muted);
}

.ai-support-error {
    margin: 8px 0 0;
    padding: 8px 10px;
    border-radius: var(--ai-r-sm);
    background: var(--ai-danger-bg);
    color: var(--ai-danger);
    font-size: 12.5px;
    line-height: 18px;
}

.ai-support-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

.ai-support-actions button {
    height: 32px;
    padding: 0 14px;
    border: 0;
    border-radius: var(--ai-r-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s ease, opacity .15s ease;
}

.ai-support-cancel { background: transparent; color: var(--ai-text-2); box-shadow: 0 0 0 1px var(--ai-border-2); }
.ai-support-cancel:hover:not(:disabled) { background: var(--ai-elev-2); }
.ai-support-send { background: var(--ai-violet); color: #fff; }
.ai-support-send:hover:not(:disabled) { background: #5a1ee0; }
.ai-support-actions button:disabled { opacity: .45; cursor: default; }
.ai-support-actions button:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; }

.ai-support-done {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.ai-support-done > i { font-size: 22px; color: #16a34a; flex-shrink: 0; margin-top: 1px; }
.ai-support-done div { flex: 1; }
.ai-support-done strong { display: block; font-size: 13.5px; font-weight: 600; color: var(--ai-text); line-height: 20px; }
.ai-support-done p { margin: 2px 0 0; font-size: 12.5px; color: var(--ai-muted); line-height: 18px; }
.ai-support-done .ai-icon-btn { margin: -4px -6px 0 0; }

.ai-link {
    display: inline;
    margin: 0 0 0 4px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ai-violet);
    font: inherit;
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: transparent;
    text-underline-offset: 2px;
    cursor: pointer;
    transition: text-decoration-color .15s ease;
}

.ai-link:hover { text-decoration-color: currentColor; }
.ai-link:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; border-radius: 3px; }
[data-bs-theme="dark"] .ai-link { color: var(--ai-violet-3); }

.ai-followups:empty { display: none; }

/* Följdfrågorna: en ren lista i svarets egen spalt. Linjerna börjar och slutar där texten gör,
   ingen negativ marginal, och hovringen färgar texten i stället för att lägga en platta. */
.ai-followups {
    margin: 16px 0 4px;
    padding-top: 12px;
    border-top: 1px solid var(--ai-border);
}

.ai-followups-title {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    color: var(--ai-muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 20px;
}

.ai-followups-title i { font-size: 14px; }

.ai-followup {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    margin: 0;
    padding: 8px 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--ai-muted);
    font-size: 13px;
    font-weight: 400;
    line-height: 20px;
    text-align: left;
    cursor: pointer;
    animation: ai-rise .45s var(--ai-ease) both;
    transition: color .15s ease;
}

.ai-followup + .ai-followup { border-top: 1px solid var(--ai-border); }
.ai-followup i { color: var(--ai-muted); font-size: 14px; flex-shrink: 0; transition: transform .3s var(--ai-spring), color .15s ease; }
.ai-followup:hover { color: var(--ai-text); }
.ai-followup:hover i { color: var(--ai-violet); transform: translate(1px, -1px); }
.ai-followup:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; border-radius: 4px; }
[data-bs-theme="dark"] .ai-followup:hover i { color: var(--ai-violet-3); }
[data-bs-theme="dark"] .ai-followup:focus-visible { outline-color: var(--ai-violet-3); }
.ai-assist[data-busy="true"] .ai-followup { opacity: .5; pointer-events: none; }

.ai-full {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 16px 0;
    color: var(--ai-muted);
    font-size: 12.5px;
}

/* "Till senaste", med en prick när svaret fortsätter nedanför. */
.ai-jump {
    left: 50%;
    bottom: 132px;
    z-index: 3;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: var(--ai-surface-solid);
    color: var(--ai-text);
    font-size: 15px;
    cursor: pointer;
    box-shadow: 0 6px 16px -8px rgba(40, 14, 110, .35), 0 0 0 1px var(--ai-border-2);
    opacity: 0;
    transform: translate(-50%, 10px) scale(.9);
    pointer-events: none;
    transition: opacity .2s ease, transform .35s var(--ai-spring);
}

.ai-assist.is-scrolled-up .ai-jump {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
}

.ai-assist.has-news .ai-jump::after {
    content: "";
    position: absolute;
    top: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ai-grad);
    border: 2px solid var(--ai-surface-solid);
    animation: ai-pop .3s var(--ai-spring);
}

/* Toast. */
.ai-toast {
    left: 50%;
    top: 70px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--ai-text);
    color: var(--ai-surface-solid);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 12px 30px -10px rgba(20, 10, 60, .5);
    opacity: 0;
    transform: translate(-50%, -8px) scale(.96);
    pointer-events: none;
    transition: opacity .2s ease, transform .35s var(--ai-spring);
}

.ai-toast:empty { display: none; }
.ai-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.ai-toast i { color: #4ade80; }

/* ── Inmatningen ─────────────────────────────────────────────────────────── */

.ai-composer {
    flex-shrink: 0;
    padding: 8px 14px 12px;
    z-index: 2;
}

.ai-assist.is-expanded .ai-composer { padding: 8px max(22px, calc((100% - 640px) / 2)) 16px; }

.ai-input-wrap {
    position: relative;
    border-radius: var(--ai-r-lg);
    background: var(--ai-surface-solid);
    box-shadow: 0 0 0 1px var(--ai-border-2), 0 6px 20px -14px rgba(40, 14, 110, .25);
    transition: box-shadow .25s ease;
}

/* En långsamt roterande spektrumkant när man skriver — dämpad, den ska kännas, inte synas först. */
.ai-input-wrap::before {
    content: "";
    position: absolute;
    inset: -1.5px;
    border-radius: calc(var(--ai-r-lg) + 1.5px);
    padding: 1.5px;
    background: var(--ai-spectrum);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity .35s ease;
    animation: ai-spin 16s linear infinite;
    pointer-events: none;
}

.ai-input-wrap:focus-within::before { opacity: .6; }
.ai-input-wrap:focus-within { box-shadow: 0 0 0 1px var(--ai-border-accent), 0 10px 28px -18px rgba(109, 39, 255, .45); }

.ai-context {
    display: flex;
    padding: 8px 12px 0;
}

.ai-context-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    padding: 2px 8px 2px 6px;
    border-radius: 6px;
    background: var(--ai-elev-2);
    color: var(--ai-muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-context-chip i { font-size: 14px; color: var(--ai-icon); }

.ai-input-row {
    position: relative;
    display: flex;
    align-items: flex-end;
}

.ai-input-row textarea {
    flex: 1;
    min-height: 50px;
    max-height: 180px;
    padding: 14px 52px 14px 16px;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: var(--ai-text);
    font: 400 14.5px/1.5 Inter, sans-serif;
    overflow-y: auto;
    scrollbar-width: thin;
}

.ai-context + .ai-input-row textarea { padding-top: 8px; min-height: 44px; }
.ai-input-row textarea::placeholder { color: var(--ai-muted); opacity: 1; }
.ai-input-row textarea:disabled { cursor: not-allowed; }

.ai-send {
    position: absolute;
    right: 8px;
    bottom: 8px;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: var(--ai-elev-2);
    color: var(--ai-muted);
    font-size: 16px;
    cursor: pointer;
    transition: background .25s ease, color .25s ease, transform .3s var(--ai-spring), box-shadow .25s ease;
}

.ai-assist.has-input .ai-send:not(.is-stop) {
    background: var(--ai-grad);
    color: #fff;
    box-shadow: 0 4px 12px -6px rgba(109, 39, 255, .6), inset 0 1px 0 rgba(255, 255, 255, .25);
}

.ai-send:active { transform: scale(.92); }
.ai-send:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; }
[data-bs-theme="dark"] .ai-send:focus-visible { outline-color: var(--ai-violet-3); }

.ai-send.is-stop {
    background: var(--ai-text);
    color: var(--ai-surface-solid);
    font-size: 14px;
}

.ai-disclaimer {
    position: relative;
    height: 16px;
    margin: 8px 4px 0;
    color: var(--ai-muted);
    font-size: 11.5px;
    line-height: 16px;
    text-align: center;
    white-space: nowrap;
}

.ai-disclaimer > span {
    position: absolute;
    inset: 0;
    transition: opacity .2s ease, transform .3s var(--ai-ease);
}

.ai-keys { opacity: 0; transform: translateY(3px); }
.ai-keys kbd {
    padding: 0 5px;
    border: 0;
    border-radius: 5px;
    background: var(--ai-tint);
    box-shadow: none;
    color: var(--ai-muted);
    font: 500 10px/16px Inter, sans-serif;
}
.ai-composer:focus-within .ai-disclaimer > span:first-child { opacity: 0; transform: translateY(-3px); }
.ai-composer:focus-within .ai-keys { opacity: 1; transform: none; }

/* ── Mobil ───────────────────────────────────────────────────────────────── */

/* Texten tonar ut mjukt under rubriken i stället för att klippas med en hård kant. */
.ai-body {
    padding-top: 14px;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px);
    mask-image: linear-gradient(to bottom, transparent 0, #000 14px);
}

/* Telefonen: brödtexten ett steg större (iOS läser 17 pt som standard), följdfrågorna efter. */
@media (max-width: 575.98px) {
    .ai-answer, .ai-bubble { font-size: 15px; }
    .ai-answer p.ai-lead { font-size: 16px; }
    .ai-followup { font-size: 14px; }
}

/* Telefonen får aldrig förstora chattens text på egen hand (iOS i liggande läge, Androids "font boosting"). */
.ai-assist { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

@media (max-width: 575.98px) {
    .ai-assist { right: 16px; bottom: 16px; }

    .ai-frame,
    .ai-assist.is-expanded .ai-frame {
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100dvh;
        transform-origin: bottom center;
        transform: translateY(40px);
    }

    .ai-panel { border-radius: 0; padding-bottom: env(safe-area-inset-bottom); }

    /* Hela skärmen, som Apple Intelligence på iPhone: en skarp regnbågskant och ett smalt, mjukt sken
       innanför skärmkanten medan assistenten arbetar. Byggt för att vara billigt att rita i Safari:
       inga blur-filter och inga animerade gradienter — kanten roterar som ett lager (transform) och
       skenet skiftar färg genom att två färdiga lager tonar i varandra (opacity). Båda sköts av
       grafikkretsen utan att något ritas om. (På datorn ligger skenet utanför panelen.) */

    /* Panelen täcker hela skärmen — frostat glas bakom den syns inte men kostar mest av allt på iOS. */
    .ai-panel { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--ai-surface-solid); }

    .ai-glow { --ai-screen-r: 0px; border-radius: var(--ai-screen-r); overflow: hidden; }

    .ai-glow-rim {
        inset: 0;
        padding: 2.5px;
        border-radius: var(--ai-screen-r);
        background: none;
        animation: none;
        overflow: hidden;
    }
    .ai-glow-rim::before {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        width: 150vmax;
        height: 150vmax;
        margin: -75vmax 0 0 -75vmax;
        background: conic-gradient(#2f7bff, #9b5cff 16%, #ff4fa3 32%, #ff7a45 46%, #ffb340 56%, #ff4fa3 70%, #9b5cff 84%, #2f7bff);
        animation: ai-rotate 6s linear infinite;
        will-change: transform;
    }

    .ai-glow-bloom,
    .ai-glow-bloom::before {
        position: absolute;
        inset: 0;
        border-radius: var(--ai-screen-r);
    }
    .ai-glow-bloom {
        z-index: 3;
        filter: none;
        opacity: 1;
        animation: none;
        /* Ljus, ingen linje: klarast vid kanten, halvvägs efter 6 px, borta efter 24 px. */
        background:
            linear-gradient(to right, rgba(47, 123, 255, .5), rgba(47, 123, 255, .16) 6px, transparent 24px),
            linear-gradient(to left, rgba(255, 79, 163, .48), rgba(255, 79, 163, .15) 6px, transparent 24px),
            linear-gradient(to bottom, rgba(155, 92, 255, .5), rgba(155, 92, 255, .16) 6px, transparent 24px),
            linear-gradient(to top, rgba(255, 138, 61, .46), rgba(255, 138, 61, .14) 6px, transparent 24px);
    }
    .ai-glow-bloom::before {
        content: "";
        opacity: 0;
        background:
            linear-gradient(to right, rgba(255, 79, 163, .48), rgba(255, 79, 163, .15) 6px, transparent 24px),
            linear-gradient(to left, rgba(47, 123, 255, .5), rgba(47, 123, 255, .16) 6px, transparent 24px),
            linear-gradient(to bottom, rgba(255, 138, 61, .44), rgba(255, 138, 61, .14) 6px, transparent 24px),
            linear-gradient(to top, rgba(155, 92, 255, .5), rgba(155, 92, 255, .16) 6px, transparent 24px);
        animation: ai-glow-swap 3.6s ease-in-out infinite;
        will-change: opacity;
    }

    /* I Safari har sidan raka kanter — en skarp kantlinje blir en rektangulär ram. Bara ljuset där;
       linjen visas i appen på hemskärmen, där den följer telefonens rundade hörn. */
    .ai-glow-rim { display: none; }

    /* Rör sig bara medan den arbetar (annars syns glöden inte ändå) — sparar batteri. */
    .ai-assist:not([data-busy="true"]) .ai-glow-rim::before,
    .ai-assist:not([data-busy="true"]) .ai-glow-bloom::before { animation-play-state: paused; }

    /* I mörkt läge lyser skenet (adderar ljus) i stället för att lägga färg ovanpå. */
    [data-bs-theme="dark"] .ai-glow-bloom { mix-blend-mode: plus-lighter; }
}

/* Som app på hemskärmen fyller Jobbs hela skärmen — då följer glöden telefonens rundade hörn. I
   Safari har sidan raka hörn (statusraden och adressfältet), och där vore rundningen fel. */
@media (max-width: 575.98px) and (pointer: coarse) and (display-mode: standalone) {
    .ai-glow { --ai-screen-r: 44px; }
    .ai-glow-rim { display: block; }
}

@keyframes ai-glow-swap { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }

@media (max-width: 575.98px) {
    .ai-hide-mobile { display: none; }

    .ai-assist[data-open="true"] .ai-launcher { opacity: 0; pointer-events: none; }
    .ai-keys { display: none; }
}

@media print {
    .ai-assist { display: none !important; }
}

/* ── Rörelse ─────────────────────────────────────────────────────────────── */

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

@keyframes ai-breathe {
    0%, 100% { opacity: .16; transform: scale(.98); }
    50% { opacity: .28; transform: scale(1.02); }
}

/* Reflexen sveper en gång i slutet av varvet och vilar resten. */
@keyframes ai-sweep {
    0%, 84% { left: -140%; }
    100% { left: 170%; }
}

@keyframes ai-drift {
    from { transform: translateX(-4%) translateY(0); }
    to { transform: translateX(4%) translateY(6px); }
}

@keyframes ai-shimmer {
    from { background-position: 100% 0; }
    to { background-position: -180% 0; }
}

@keyframes ai-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

@keyframes ai-rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

@keyframes ai-pop {
    from { opacity: 0; transform: scale(.5); }
    to { opacity: 1; transform: none; }
}

@keyframes ai-word {
    from { opacity: 0; filter: blur(4px); }
    to { opacity: 1; filter: blur(0); }
}

@keyframes ai-caret {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .35; transform: scale(.65); }
}

@keyframes ai-pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(109, 39, 255, .28); }
    100% { box-shadow: 0 0 0 6px rgba(109, 39, 255, 0); }
}

/* Samma puls, men stegets egen ring (inset) ligger kvar under den. */
@keyframes ai-pulse-step {
    0% { box-shadow: inset 0 0 0 1.5px var(--ai-border-accent), 0 0 0 0 rgba(109, 39, 255, .28); }
    100% { box-shadow: inset 0 0 0 1.5px var(--ai-border-accent), 0 0 0 6px rgba(109, 39, 255, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .ai-assist *,
    .ai-assist *::before,
    .ai-assist *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

/* ── Bifogade bilder — skärmbild som fråga (ai-attach.js) ────────────────── */
/* Brickan, statusraden och miniatyrerna i bubblan fylls av JS; Blazor renderar tomma behållare. */

.ai-attach-tray { padding: 10px 12px 0; }
.ai-attach-tray:empty { display: none; }

.ai-attach-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0;
    padding: 6px 0 0;
    list-style: none;
}

.ai-attach-item {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: var(--ai-r-md);
    background: var(--ai-elev-2);
    box-shadow: 0 0 0 1px var(--ai-border-2);
    animation: ai-pop .3s var(--ai-spring) both;
}

.ai-attach-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

.ai-attach-spinner {
    position: absolute;
    inset: 0;
    width: 20px;
    height: 20px;
    margin: auto;
    border: 2px solid var(--ai-border-2);
    border-top-color: var(--ai-violet);
    border-radius: 50%;
    animation: ai-rotate .8s linear infinite;
}

[data-bs-theme="dark"] .ai-attach-spinner { border-top-color: var(--ai-violet-3); }

.ai-attach-remove {
    position: absolute;
    top: -7px;
    right: -7px;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 2px solid var(--ai-surface-solid);
    border-radius: 50%;
    background: var(--ai-text);
    color: var(--ai-surface-solid);
    font-size: 11px;
    cursor: pointer;
    transition: transform .2s var(--ai-spring);
}

/* Större träffyta än det syns — en 22 px-knapp är för liten för ett finger. */
.ai-attach-remove::before {
    content: "";
    position: absolute;
    inset: -9px;
}

.ai-attach-remove:hover { transform: scale(1.08); }
.ai-attach-remove:active { transform: scale(.92); }
.ai-attach-remove:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; }
[data-bs-theme="dark"] .ai-attach-remove:focus-visible { outline-color: var(--ai-violet-3); }

.ai-attach-note,
.ai-attach-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin: 10px 2px 0;
    color: var(--ai-muted);
    font-size: 12px;
    line-height: 16px;
}

.ai-attach-note i,
.ai-attach-error i { flex-shrink: 0; margin-top: 1px; font-size: 14px; }
.ai-attach-note i { color: var(--ai-icon); }
.ai-attach-error { color: var(--ai-danger); font-weight: 500; }

/* Bara för skärmläsare: "Bild bifogad. 1 av 2." */
.ai-attach-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Gemet står till vänster om skicka-knappen; texten får inte löpa in under dem. */
.ai-attach-btn {
    position: absolute;
    right: 44px;
    bottom: 8px;
}

.ai-input-row textarea { padding-right: 84px; }

/* Dra in en bild över panelen. */
.ai-assist.is-dropping .ai-input-wrap { box-shadow: 0 0 0 2px var(--ai-violet), 0 10px 28px -18px rgba(109, 39, 255, .45); }
[data-bs-theme="dark"] .ai-assist.is-dropping .ai-input-wrap { box-shadow: 0 0 0 2px var(--ai-violet-3); }

.ai-assist.is-dropping .ai-input-wrap::after {
    content: "Släpp bilden för att bifoga den";
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-items: center;
    border-radius: inherit;
    background: var(--ai-surface-solid);
    color: var(--ai-violet);
    font-size: 13px;
    font-weight: 600;
    pointer-events: none;
}

[data-bs-theme="dark"] .ai-assist.is-dropping .ai-input-wrap::after { color: var(--ai-violet-3); }

/* Miniatyrerna i användarens bubbla. */
.ai-bubble-images {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    margin: 2px 0 8px;
    white-space: normal;
}

.ai-bubble-images:empty { display: none; }

.ai-bubble-images img {
    display: block;
    max-width: min(200px, 100%);
    max-height: 150px;
    border-radius: 10px;
    object-fit: cover;
    background: var(--ai-surface-solid);
    box-shadow: 0 0 0 1px var(--ai-border-2);
}

/* ── Hälsokollen (Shared/AiHelp/AiHealthCard.razor) ──────────────────────── */
/* Ett diskret kort överst i tomläget: vad som behöver ses över i företagets inställningar.
   Texten i märkena är mörkare än --ai-danger så att den håller 4.5:1 även på den tonade bakgrunden. */

.ai-assist {
    --ai-health-block: #b3203a;
    --ai-health-block-bg: rgba(217, 45, 69, .08);
    --ai-health-warn: #8a5300;
    --ai-health-warn-bg: rgba(245, 158, 11, .14);
}

[data-bs-theme="dark"] .ai-assist {
    --ai-health-block: #ff8a9b;
    --ai-health-block-bg: rgba(255, 107, 129, .13);
    --ai-health-warn: #fbbf24;
    --ai-health-warn-bg: rgba(251, 191, 36, .12);
}

.ai-health {
    margin: 12px 0 0;
    padding: 12px 12px 8px;
    border: 1px solid var(--ai-border-2);
    border-radius: var(--ai-r-lg);
    background: var(--ai-surface-solid);
    box-shadow: 0 1px 2px rgba(24, 16, 64, .04), 0 10px 24px -18px rgba(40, 14, 110, .35);
    text-align: left;
    animation: ai-rise .45s var(--ai-ease) both;
}

.ai-health + .ai-hero { padding-top: 20px; }

.ai-health-head {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 0 0 8px 2px;
}

.ai-health-badge {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: var(--ai-r-sm);
    background: var(--ai-tint);
    color: var(--ai-violet);
    font-size: 18px;
}

.ai-health-badge.is-blocking { background: var(--ai-health-block-bg); color: var(--ai-health-block); }
[data-bs-theme="dark"] .ai-health-badge:not(.is-blocking) { color: var(--ai-violet-3); }

.ai-health-heading { flex: 1; min-width: 0; }

.ai-health-heading h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 20px;
    letter-spacing: -.01em;
    color: var(--ai-text);
}

.ai-health-heading p {
    margin: 1px 0 0;
    font-size: 12.5px;
    line-height: 17px;
    color: var(--ai-muted);
}

.ai-health-list {
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid var(--ai-border);
}

.ai-health-list li + li { border-top: 1px solid var(--ai-border); }

/* Raden är antingen en länk (sidan där felet åtgärdas) eller en knapp (fråga Jobbs AI). */
.ai-health-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    margin: 0;
    padding: 8px 6px 8px 2px;
    border: 0;
    border-radius: var(--ai-r-sm);
    background: transparent;
    color: var(--ai-text);
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s ease;
}

.ai-health-row:hover { background: var(--ai-tint); color: var(--ai-text); }
.ai-health-row:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 1px; }
[data-bs-theme="dark"] .ai-health-row:focus-visible { outline-color: var(--ai-violet-3); }

.ai-health-sev {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    min-width: 84px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    white-space: nowrap;
}

.ai-health-sev i { font-size: 12px; }
.ai-health-sev.is-blocking { background: var(--ai-health-block-bg); color: var(--ai-health-block); }
.ai-health-sev.is-warning { background: var(--ai-health-warn-bg); color: var(--ai-health-warn); }

.ai-health-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.ai-health-text strong {
    font-size: 13px;
    font-weight: 600;
    line-height: 18px;
    color: var(--ai-text);
}

.ai-health-text small {
    font-size: 12px;
    line-height: 17px;
    color: var(--ai-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-health-go {
    flex-shrink: 0;
    font-size: 14px;
    color: var(--ai-icon);
    transition: transform .3s var(--ai-spring), color .15s ease;
}

.ai-health-row:hover .ai-health-go { color: var(--ai-violet); transform: translateX(2px); }
[data-bs-theme="dark"] .ai-health-row:hover .ai-health-go { color: var(--ai-violet-3); }

.ai-health-ask {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    margin: 4px 0 0;
    padding: 6px 8px;
    border: 0;
    border-radius: var(--ai-r-sm);
    background: transparent;
    color: var(--ai-violet);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease;
}

.ai-health-ask i { font-size: 16px; }
.ai-health-ask:hover { background: var(--ai-tint); }
.ai-health-ask:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 1px; }
[data-bs-theme="dark"] .ai-health-ask { color: var(--ai-violet-3); }
[data-bs-theme="dark"] .ai-health-ask:focus-visible { outline-color: var(--ai-violet-3); }

/* Smal panel (mobil): märket på egen rad så att rubriken får hela bredden. */
@media (max-width: 575.98px) {
    .ai-health-row { flex-wrap: wrap; row-gap: 4px; }
    .ai-health-sev { min-width: 0; }
    .ai-health-text { flex-basis: calc(100% - 30px); order: 1; }
    .ai-health-go { order: 2; }
    .ai-health-text small { white-space: normal; }
}

/* ══════════════════════════════════════════════════════════════════════════
   Svarens form: nyckeltal, tabeller, rutor, diagram och knappar
   Renderas av ai-markdown.js / ai-chart.js (JS-ägt) och AiActionButtons.razor.
   Egna tokens nedan, ljust och mörkt läge.
   ══════════════════════════════════════════════════════════════════════════ */

.ai-assist {
    --ai-up: #0f7b3f;
    --ai-up-bg: rgba(15, 123, 63, .08);
    --ai-down: #c0283a;
    --ai-down-bg: rgba(192, 40, 58, .07);
    --ai-note-bg: rgba(109, 39, 255, .05);
    --ai-warn: #9a5b00;
    --ai-warn-bg: rgba(214, 138, 0, .09);
    --ai-chart-bar: #7c3aed;
    --ai-chart-bar-hi: #5b21b6;
    --ai-chart-neg: #d4668f;
    --ai-chart-grid: rgba(24, 16, 64, .08);
    --ai-card: #ffffff;
}

[data-bs-theme="dark"] .ai-assist {
    --ai-up: #4ade80;
    --ai-up-bg: rgba(74, 222, 128, .1);
    --ai-down: #ff7a8a;
    --ai-down-bg: rgba(255, 122, 138, .1);
    --ai-note-bg: rgba(167, 139, 250, .08);
    --ai-warn: #f5c451;
    --ai-warn-bg: rgba(245, 196, 81, .1);
    --ai-chart-bar: #a78bfa;
    --ai-chart-bar-hi: #c4b5fd;
    --ai-chart-neg: #f49ab8;
    --ai-chart-grid: rgba(255, 255, 255, .08);
    --ai-card: #1c1929;
}

.ai-sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ── Typografi ── */

.ai-answer { font-variant-numeric: tabular-nums; }
.ai-answer p { margin: 0 0 .9em; }
.ai-answer p.ai-lead {
    font-size: 15px;
    font-weight: 500;
    line-height: 1.55;
    letter-spacing: -.005em;
    color: var(--ai-text);
}

/* Länkar till admin-sidor: diskreta chips med pil. */
.ai-answer a {
    display: inline-flex;
    align-items: baseline;
    gap: 2px;
    margin: 0 1px;
    padding: 0 8px 0 9px;
    border: 1px solid var(--ai-tint-2);
    border-radius: 999px;
    background: var(--ai-tint);
    color: var(--ai-text);
    font-size: .93em;
    font-weight: 500;
    line-height: 1.55;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.ai-answer a::after { margin-left: 1px; }
.ai-answer a:hover { background: var(--ai-tint-2); border-color: var(--ai-border-accent); color: var(--ai-violet); }
[data-bs-theme="dark"] .ai-answer a:hover { color: var(--ai-violet-3); }

/* Knappen trycktes innan chatten var uppkopplad: den pulserar tills chatten öppnas. */
.ai-launcher.is-waking { animation: ai-launcher-wake 1s ease-in-out infinite; }
@keyframes ai-launcher-wake { 0%, 100% { transform: scale(1); } 50% { transform: scale(.92); } }

/* ── Märket: squircle med gnista (ersätter glaskulan) ── */

.ai-mark {
    position: relative;
    display: inline-grid;
    flex-shrink: 0;
    place-items: center;
    background: linear-gradient(135deg, #6d28d9 0%, #8b5cf6 38%, #c026d3 72%, #ec4899 100%);
    background-size: 150% 150%;
    background-position: 20% 20%;
    color: #fff;
    box-shadow:
        inset 0 0 0 .5px rgba(255, 255, 255, .3),
        inset 0 1px 0 rgba(255, 255, 255, .22),
        0 1px 2px rgba(40, 14, 110, .16),
        0 6px 14px -8px rgba(109, 39, 255, .55);
}
.ai-mark svg { width: 64%; height: 64%; fill: currentColor; overflow: visible; filter: drop-shadow(0 .5px .5px rgba(60, 10, 120, .28)); }
.ai-mark-spark { opacity: .9; transform-origin: 18.6px 17.3px; }
.ai-mark.xs { width: 22px; height: 22px; border-radius: 6.5px; }
.ai-mark.sm { width: 30px; height: 30px; border-radius: 9px; }
.ai-mark.lg { width: 56px; height: 56px; border-radius: 16px; animation: ai-float 9s ease-in-out infinite; }

/* Arbetar: gradienten flyter och gnistan tindrar — lugnt, kanten runt panelen bär huvudsignalen. */
.ai-assist[data-busy="true"] .ai-header .ai-mark,
.ai-msg-assistant.is-live .ai-mark.xs { animation: ai-mark-flow 3.2s ease-in-out infinite; }
.ai-assist[data-busy="true"] .ai-header .ai-mark svg,
.ai-msg-assistant.is-live .ai-mark.xs svg { animation: ai-mark-twinkle 1.8s ease-in-out infinite; }
.ai-assist[data-busy="true"] .ai-header .ai-mark-spark,
.ai-msg-assistant.is-live .ai-mark.xs .ai-mark-spark { animation: ai-mark-spark 1.8s ease-in-out infinite; }

@keyframes ai-mark-flow { 0%, 100% { background-position: 20% 20%; } 50% { background-position: 100% 100%; } }
@keyframes ai-mark-twinkle { 0%, 100% { transform: scale(1) rotate(0deg); } 50% { transform: scale(.88) rotate(10deg); } }
@keyframes ai-mark-spark { 0%, 100% { opacity: .9; transform: scale(1); } 50% { opacity: .35; transform: scale(.6); } }

/* ── Svar utan siffror: steg, menyvägar, knappnamn, listor, rubriker ── */

/* Steg: numrerade cirklar i samma gradient som resten, med en tunn linje mellan stegen. */
.ai-answer > ol { list-style: none; counter-reset: ai-step; margin: .25em 0 1em; padding-left: 0; }
.ai-answer > ol > li { position: relative; counter-increment: ai-step; margin: 0; padding: 2px 0 12px 36px; }
.ai-answer > ol > li:last-child { padding-bottom: 2px; }
.ai-answer > ol > li::before {
    content: counter(ai-step);
    position: absolute;
    top: 0;
    left: 0;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--ai-grad);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 3px 10px -4px rgba(109, 39, 255, .55);
}
.ai-answer > ol > li:not(:last-child)::after {
    content: "";
    position: absolute;
    top: 28px;
    bottom: 2px;
    left: 11.5px;
    width: 1px;
    background: linear-gradient(var(--ai-border-accent), var(--ai-border-2));
}

/* Knapp- och fältnamn i stegen (fetstil enligt instruktionerna) ser ut som etiketter i gränssnittet. */
.ai-answer ol strong,
.ai-answer strong:has(.ai-arrow) {
    display: inline;
    padding: 1px 6px;
    border-radius: 6px;
    background: var(--ai-elev);
    box-shadow: inset 0 0 0 1px var(--ai-border-2);
    color: var(--ai-text);
    font-size: .94em;
    font-weight: 600;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
}

/* Ett knappnamn bryts aldrig mitt i; en lång menyväg får brytas (vid pilarna). */
.ai-answer ol strong:not(:has(.ai-arrow)) { white-space: nowrap; }

/* Menyvägar som brödsmula: "Handel → Försäljning → Artiklar". */
.ai-arrow { margin: 0 1px; color: var(--ai-violet); font-weight: 500; }
[data-bs-theme="dark"] .ai-arrow { color: var(--ai-violet-3); }

/* Punktlistor: små prickar i accentfärgen. */
.ai-answer ul { list-style: none; padding-left: 1.15em; }
.ai-answer ul > li { position: relative; }
.ai-answer ul > li::before {
    content: "";
    position: absolute;
    top: .66em;
    left: -.95em;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--ai-violet);
    opacity: .65;
}
[data-bs-theme="dark"] .ai-answer ul > li::before { background: var(--ai-violet-3); }

/* Rubriker med ett kort gradientstreck — sektioner går att skumma. */
.ai-answer h3, .ai-answer h4 { display: flex; align-items: center; gap: 8px; }
.ai-answer h3::before, .ai-answer h4::before {
    content: "";
    flex-shrink: 0;
    width: 3px;
    height: 14px;
    border-radius: 2px;
    background: var(--ai-grad);
}

/* Markören hör till text, inte till brickor, tabeller och rutor. */
.ai-answer.is-streaming > :is(.ai-kpis, .ai-table-wrap, .ai-callout):last-child::after { content: none; }

/* ── Nyckeltal ── */

.ai-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
    gap: 8px;
    margin: 2px 0 14px;
}

.ai-kpi {
    min-width: 0;
    padding: 10px 12px 11px;
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-r-md);
    background: linear-gradient(180deg, var(--ai-card), var(--ai-elev));
    box-shadow: 0 1px 2px rgba(24, 16, 64, .04);
}
.ai-kpi.is-new { animation: ai-rise .45s var(--ai-ease) both; }

.ai-kpi dt, .ai-kpi dd { margin: 0; }
.ai-kpi-label {
    overflow: hidden;
    color: var(--ai-muted);
    font-size: 11.5px;
    font-weight: 500;
    line-height: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ai-kpi .ai-kpi-value {
    margin-top: 2px;
    color: var(--ai-text);
    font-size: 19px;
    font-weight: 600;
    letter-spacing: -.02em;
    line-height: 26px;
    overflow-wrap: anywhere;
}
.ai-kpi .ai-kpi-delta {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    max-width: 100%;
    margin-top: 5px;
    padding: 1px 7px;
    border-radius: 7px;
    font-size: 11.5px;
    font-weight: 500;
    line-height: 17px;
}
.ai-kpi-delta span { font-size: 8px; }
.ai-kpi-delta.is-up { background: var(--ai-up-bg); color: var(--ai-up); }
.ai-kpi-delta.is-down { background: var(--ai-down-bg); color: var(--ai-down); }
.ai-kpi-delta.is-flat { background: var(--ai-elev-2); color: var(--ai-muted); }

/* ── Tabeller ── */

.ai-table-wrap {
    margin: 4px 0 14px;
    overflow-x: auto;
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-r-md);
    background: var(--ai-card);
    -webkit-overflow-scrolling: touch;
}
.ai-table-wrap:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; }
[data-bs-theme="dark"] .ai-table-wrap:focus-visible { outline-color: var(--ai-violet-3); }

.ai-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    line-height: 1.45;
}
.ai-table th, .ai-table td {
    padding: 7px 10px;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}
.ai-table td:first-child { min-width: 96px; white-space: normal; }
.ai-table th {
    border-bottom: 1px solid var(--ai-border-2);
    background: var(--ai-elev);
    color: var(--ai-muted);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .01em;
}
.ai-table tbody tr:nth-child(even) td { background: var(--ai-tint); }
.ai-table tbody tr + tr td { border-top: 1px solid var(--ai-border); }
.ai-table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.ai-table th.is-num { text-align: right; }
.ai-table td.is-up { color: var(--ai-up); font-weight: 600; }
.ai-table td.is-down { color: var(--ai-down); font-weight: 600; }
.ai-delta-glyph { margin-right: 4px; font-size: .78em; vertical-align: 1px; }
.ai-table td strong { color: var(--ai-text); }

/* ── Framhävda rutor ── */

.ai-callout {
    display: flex;
    gap: 9px;
    margin: 4px 0 14px;
    padding: 10px 12px;
    border-radius: var(--ai-r-md);
    background: var(--ai-note-bg);
    color: var(--ai-text-2);
    font-size: 13.5px;
    line-height: 1.55;
}
.ai-callout > i { flex-shrink: 0; margin-top: 2px; color: var(--ai-violet); font-size: 16px; }
.ai-callout strong:first-child { color: var(--ai-text); }
.ai-callout.is-important { background: var(--ai-warn-bg); }
.ai-callout.is-important > i { color: var(--ai-warn); }
.ai-callout.is-tip > i { color: var(--ai-up); }
[data-bs-theme="dark"] .ai-callout.is-note > i { color: var(--ai-violet-3); }

/* ── Diagram ── */

/* minmax(0, 1fr) och min-width: 0 — en ritning i gammal bredd får aldrig trycka ut panelen; den mäts om. */
.ai-charts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin: 12px 0 4px; }
.ai-charts > .ai-chart { min-width: 0; }
.ai-charts:empty { display: none; }

.ai-chart {
    margin: 0;
    padding: 12px 12px 10px;
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-r-lg);
    background: var(--ai-card);
    box-shadow: 0 1px 2px rgba(24, 16, 64, .04);
}
.ai-chart.is-entering { animation: ai-rise .5s var(--ai-ease) both; }

.ai-chart-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}
.ai-chart-title { color: var(--ai-text); font-size: 13px; font-weight: 600; letter-spacing: -.01em; }
.ai-chart-unit { flex-shrink: 0; color: var(--ai-muted); font-size: 11.5px; }

.ai-chart-plot { position: relative; border-radius: var(--ai-r-sm); outline: none; }
.ai-chart-plot:focus-visible { box-shadow: 0 0 0 2px var(--ai-card), 0 0 0 4px var(--ai-violet); }
[data-bs-theme="dark"] .ai-chart-plot:focus-visible { box-shadow: 0 0 0 2px var(--ai-card), 0 0 0 4px var(--ai-violet-3); }
.ai-chart-plot svg { display: block; overflow: visible; }

.ai-chart text { font-family: inherit; font-size: 11px; }
.ai-chart-axis { fill: var(--ai-muted); }
.ai-chart-label { fill: var(--ai-text-2); }
.ai-chart-value { fill: var(--ai-text); font-weight: 600; font-variant-numeric: tabular-nums; }
.ai-chart-grid { stroke: var(--ai-chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.ai-chart-grid.is-zero { stroke: var(--ai-border-2); }

.ai-chart-bar { fill: var(--ai-chart-bar); transform-box: fill-box; transition: fill .15s ease, opacity .15s ease; }
.ai-chart-bar.is-neg { fill: var(--ai-chart-neg); }
.ai-chart-plot[data-active] .ai-chart-bar:not(.is-active) { opacity: .45; }
.ai-chart-bar.is-active { fill: var(--ai-chart-bar-hi); }
.ai-chart-bar.is-rank:not(.is-top):not(.is-active) { opacity: .42; }
.ai-chart-plot[data-active] .ai-chart-bar.is-rank:not(.is-active) { opacity: .3; }

.ai-chart.is-entering[data-kind="cols"] .ai-chart-bar { transform-origin: bottom; animation: ai-bar-grow-y .6s var(--ai-ease) both; animation-delay: var(--d, 0ms); }
.ai-chart.is-entering[data-kind="cols"] .ai-chart-bar.is-neg { transform-origin: top; }
.ai-chart.is-entering[data-kind="rows"] .ai-chart-bar { transform-origin: left; animation: ai-bar-grow-x .6s var(--ai-ease) both; animation-delay: var(--d, 0ms); }
.ai-chart.is-entering[data-kind="rows"] .ai-chart-bar.is-neg { transform-origin: right; }

.ai-chart-line { fill: none; stroke: var(--ai-chart-bar); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ai-chart.is-entering .ai-chart-line { stroke-dasharray: 2400; animation: ai-line-draw 1s var(--ai-ease) both; }
.ai-chart-area-top { stop-color: var(--ai-chart-bar); stop-opacity: .22; }
.ai-chart-area-bottom { stop-color: var(--ai-chart-bar); stop-opacity: 0; }
.ai-chart-end { fill: var(--ai-card); stroke: var(--ai-chart-bar); stroke-width: 2; }
.ai-chart-guide { stroke: var(--ai-border-2); stroke-dasharray: 3 3; opacity: 0; }
.ai-chart-dot { fill: var(--ai-chart-bar); stroke: var(--ai-card); stroke-width: 2; opacity: 0; }
.ai-chart-guide.is-on, .ai-chart-dot.is-on { opacity: 1; }

.ai-chart-hit { fill: transparent; cursor: crosshair; }

.ai-chart-tip {
    position: absolute;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 6px 9px;
    border-radius: var(--ai-r-sm);
    background: var(--ai-text);
    color: var(--ai-surface-solid);
    font-size: 11.5px;
    line-height: 1.35;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 6px 18px rgba(18, 16, 34, .22);
}
.ai-chart-tip[hidden] { display: none; }
.ai-chart-tip span { opacity: .78; }
.ai-chart-tip strong { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

@keyframes ai-bar-grow-y { from { transform: scaleY(0); } to { transform: none; } }
@keyframes ai-bar-grow-x { from { transform: scaleX(0); } to { transform: none; } }
@keyframes ai-line-draw { from { stroke-dashoffset: 2400; } to { stroke-dashoffset: 0; } }

/* ── Knappar: öppna rätt vy ── */

.ai-goto { display: grid; gap: 6px; margin: 12px 0 2px; }

.ai-goto-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin: 0;
    padding: 8px 12px 8px 8px;
    border: 1px solid var(--ai-border-2);
    border-radius: var(--ai-r-md);
    background: var(--ai-card);
    color: var(--ai-text);
    font-size: inherit;
    text-align: left;
    cursor: pointer;
    animation: ai-rise .45s var(--ai-ease) both;
    animation-delay: calc(var(--i, 0) * 70ms);
    transition: border-color .15s ease, background-color .15s ease, box-shadow .2s ease, transform .2s var(--ai-spring);
}
.ai-goto-btn:hover { border-color: var(--ai-border-accent); background: var(--ai-tint); box-shadow: 0 2px 10px rgba(109, 39, 255, .08); }
.ai-goto-btn:active { transform: scale(.99); }
.ai-goto-btn:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; }
[data-bs-theme="dark"] .ai-goto-btn:focus-visible { outline-color: var(--ai-violet-3); }

.ai-goto-icon {
    display: grid;
    flex-shrink: 0;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--ai-tint-2);
    color: var(--ai-violet);
    font-size: 17px;
}
[data-bs-theme="dark"] .ai-goto-icon { color: var(--ai-violet-3); }
.ai-goto-btn.is-create .ai-goto-icon { background: var(--ai-grad); color: #fff; }

.ai-goto-text { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.ai-goto-text strong { font-size: 13.5px; font-weight: 600; line-height: 19px; }
.ai-goto-text small {
    overflow: hidden;
    color: var(--ai-muted);
    font-size: 12px;
    line-height: 17px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ai-goto-go { flex-shrink: 0; color: var(--ai-muted); font-size: 15px; transition: transform .25s var(--ai-spring), color .15s ease; }
.ai-goto-btn:hover .ai-goto-go { color: var(--ai-violet); transform: translateX(2px); }
[data-bs-theme="dark"] .ai-goto-btn:hover .ai-goto-go { color: var(--ai-violet-3); }
.ai-assist[data-busy="true"] .ai-goto-btn { opacity: .55; pointer-events: none; }

@media (max-width: 575.98px) {
    .ai-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ai-kpi .ai-kpi-value { font-size: 17px; line-height: 23px; }
    .ai-chart { padding: 10px 10px 8px; }
}

@media (prefers-reduced-motion: reduce) {
    .ai-chart.is-entering .ai-chart-bar,
    .ai-chart.is-entering .ai-chart-line { animation: none !important; stroke-dasharray: none; }
}

/* ── Förifylld panel (admins egna paneler, utanför chatten) ── */

.ai-prefill-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0 0 16px;
    padding: 10px 12px;
    border: 1px solid rgba(109, 39, 255, .22);
    border-radius: 12px;
    background: rgba(109, 39, 255, .06);
    color: #2b283f;
    font-size: 13px;
    line-height: 1.5;
}
.ai-prefill-banner > i { flex-shrink: 0; margin-top: 1px; color: #6d27ff; font-size: 17px; }
.ai-prefill-banner strong { color: #121022; }
[data-bs-theme="dark"] .ai-prefill-banner { border-color: rgba(167, 139, 250, .3); background: rgba(167, 139, 250, .1); color: #dcdae8; }
[data-bs-theme="dark"] .ai-prefill-banner > i { color: #b69cff; }
[data-bs-theme="dark"] .ai-prefill-banner strong { color: #f1f0f8; }

[data-ai-filled] > .form-label::after {
    content: "Ifyllt av Jobbs AI";
    margin-left: 8px;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(109, 39, 255, .08);
    color: #5b21b6;
    font-size: 11px;
    font-weight: 500;
}
[data-bs-theme="dark"] [data-ai-filled] > .form-label::after { background: rgba(167, 139, 250, .14); color: #c4b5fd; }

/* ── Lås upp: kort som användaren trycker och bekräftar; svaret kommer från låset ── */

.ai-unlock { display: grid; gap: 6px; margin: 12px 0 2px; }
.ai-unlock-choose { margin: 0 0 2px; color: var(--ai-muted); font-size: 12.5px; }

.ai-unlock-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 8px 6px;
    border: 1px solid var(--ai-border-2);
    border-radius: var(--ai-r-sm);
    color: var(--ai-text);
}
.ai-unlock-card.is-confirm { border-color: var(--ai-border-accent); background: var(--ai-tint); }

.ai-unlock-icon {
    display: grid;
    flex-shrink: 0;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--ai-tint-2);
    color: var(--ai-violet);
    font-size: 17px;
}
[data-bs-theme="dark"] .ai-unlock-icon { color: var(--ai-violet-3); }

.ai-unlock-text { display: flex; flex: 1; flex-direction: column; min-width: 140px; }
.ai-unlock-text strong { font-size: 13.5px; font-weight: 600; line-height: 19px; }
.ai-unlock-text small { color: var(--ai-muted); font-size: 12px; line-height: 17px; }

.ai-unlock-act { display: flex; flex-shrink: 0; align-items: center; margin-left: auto; font-size: 12.5px; }
.ai-unlock-confirm, .ai-unlock-result { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.ai-unlock-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid var(--ai-border-accent);
    border-radius: 999px;
    background: transparent;
    color: var(--ai-violet);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
[data-bs-theme="dark"] .ai-unlock-btn { color: var(--ai-violet-3); }
.ai-unlock-btn.is-go { border-color: transparent; background: var(--ai-grad); color: #fff; }
.ai-unlock-btn:disabled { opacity: .5; cursor: default; }
.ai-unlock-btn:focus-visible, .ai-unlock-cancel:focus-visible { outline: 2px solid var(--ai-violet); outline-offset: 2px; }

.ai-unlock-cancel {
    min-height: 32px;
    padding: 0 8px;
    border: 0;
    background: transparent;
    color: var(--ai-muted);
    font: inherit;
    cursor: pointer;
}
.ai-unlock-cancel:hover { color: var(--ai-text); }

.ai-unlock-wait { display: inline-flex; align-items: center; gap: 6px; color: var(--ai-muted); font-variant-numeric: tabular-nums; }
.ai-unlock-wait i { animation: ai-unlock-spin 1s linear infinite; }
.ai-unlock-result.is-ok { color: #1a8f4c; font-weight: 600; }
[data-bs-theme="dark"] .ai-unlock-result.is-ok { color: #5fd08f; }
.ai-unlock-result.is-fail { color: var(--ai-danger); }
.ai-unlock-result span { display: inline-flex; align-items: center; gap: 6px; }
.ai-unlock-problem { display: inline-flex; align-items: center; gap: 6px; color: var(--ai-muted); }

@keyframes ai-unlock-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ai-unlock-wait i { animation: none; } }
