*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #080b0f;
    --surface: #10161d;
    --surface-2: #151c24;
    --surface-3: #1b242e;
    --ink: #eef4f8;
    --text: #d6e0e6;
    --muted: #8ea0aa;
    --faint: #60717c;
    --line: #27313a;
    --line-strong: #394854;
    --blue: #2d7ff0;
    --linkedin-blue: #0a66c2;
    --linkedin-blue-soft: rgba(10, 102, 194, .16);
    --status-blue: #0ea5e9;
    --status-blue-soft: rgba(14, 165, 233, .16);
    --status-accent: #e54646;
    --status-accent-soft: rgba(229, 70, 70, .12);
    --green: #32b36b;
    --red: #f15b50;
    --amber: #e4a02b;
    --paper: #f7f4ef;
    --shadow: 0 20px 50px rgba(0, 0, 0, .28);
    --font: "Inter", ui-sans-serif, "Segoe UI", Calibri, system-ui, sans-serif;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background:
        linear-gradient(135deg, rgba(45, 127, 240, .11), transparent 28%),
        linear-gradient(315deg, rgba(50, 179, 107, .08), transparent 31%),
        var(--bg);
}

button, textarea { font: inherit; }

#app {
    display: grid;
    grid-template-columns: var(--sidebar-w, 244px) 5px minmax(380px, 1fr) 5px var(--sources-w, 460px);
    height: 100vh;
    height: 100dvh;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    overflow: hidden;
    position: relative;
}

#sidebar,
#chat,
#sources {
    min-width: 0;
    min-height: 0;
}

#sidebar     { grid-column: 1; grid-row: 1; }
#resize-left { grid-column: 2; grid-row: 1; }
#chat        { grid-column: 3; grid-row: 1; }
#resize-right{ grid-column: 4; grid-row: 1; }
#sources     { grid-column: 5; grid-row: 1; }

.resize-handle {
    background: var(--line);
    cursor: col-resize;
    touch-action: none;
    transition: background 0.15s;
    z-index: 10;
}

.resize-handle:hover,
.resize-handle.dragging {
    background: var(--blue);
}

#sidebar,
#sources {
    background: rgba(16, 22, 29, .96);
    backdrop-filter: blur(16px);
}

/* Sidebar */
#sidebar {
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
}

#sidebar-header {
    min-height: 66px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand-lockup {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 10px;
}

.brand-mark {
    width: 34px;
    height: 34px;
    object-fit: contain;
    border-radius: 8px;
    background: var(--paper);
    padding: 5px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, .28);
}

.brand-name {
    color: var(--ink);
    font-size: 15px;
    font-weight: 850;
    line-height: 1.05;
    letter-spacing: .02em;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 10px;
    font-weight: 650;
    letter-spacing: .12em;
    margin-top: 3px;
    text-transform: uppercase;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--muted);
    box-shadow: 0 0 0 4px rgba(142, 160, 170, .11);
    transition: background .3s, box-shadow .3s;
    flex-shrink: 0;
}

.status-dot.ok {
    background: var(--green);
    box-shadow: 0 0 0 4px rgba(50, 179, 107, .15), 0 0 18px rgba(50, 179, 107, .44);
}

.status-dot.error {
    background: var(--red);
    box-shadow: 0 0 0 4px rgba(241, 91, 80, .15), 0 0 18px rgba(241, 91, 80, .44);
}

#doc-list-container { flex: 1; overflow-y: auto; padding: 15px 10px; }

.section-label {
    color: var(--muted);
    font-size: 10px;
    font-weight: 850;
    letter-spacing: .14em;
    line-height: 1;
    padding: 0 8px 10px;
    text-transform: uppercase;
}

.library-overview {
    margin: 0 0 18px;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(45, 127, 240, .10), transparent 44%),
        rgba(21, 28, 36, .86);
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
}

.overview-stat {
    min-width: 0;
    min-height: 50px;
    padding: 8px 6px;
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
}

.overview-stat span {
    display: block;
    color: #fff;
    font-size: 15px;
    font-weight: 900;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.overview-stat small {
    display: block;
    color: var(--muted);
    font-size: 9.5px;
    font-weight: 750;
    line-height: 1.15;
    margin-top: 5px;
}

.overview-lines {
    display: grid;
    gap: 7px;
    margin-top: 10px;
}

.overview-lines div {
    min-width: 0;
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 8px;
    align-items: baseline;
}

.overview-lines span {
    color: var(--faint);
    font-size: 10px;
    font-weight: 850;
    text-transform: uppercase;
}

.overview-lines strong {
    min-width: 0;
    color: var(--text);
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.overview-loading,
.overview-empty {
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
    line-height: 1.4;
}

.doc-item {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font: inherit;
    margin-bottom: 5px;
    text-align: left;
    transition: background .15s, border-color .15s, transform .15s;
}

.doc-item:hover,
.doc-item:focus-visible {
    background: rgba(255, 255, 255, .035);
    border-color: rgba(255, 255, 255, .08);
    outline: none;
    transform: translateX(2px);
}

.doc-item.source-active {
    border-color: rgba(45, 127, 240, .48);
    background: rgba(45, 127, 240, .055);
    box-shadow: inset 0 0 0 1px rgba(45, 127, 240, .16);
}

.doc-name {
    display: block;
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-meta {
    display: block;
    color: var(--muted);
    font-size: 10.5px;
    line-height: 1.35;
    margin-top: 4px;
}

.classification-confidence-badge {
    flex: 0 0 52px;
    max-width: 52px;
    min-height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    padding: 3px 6px;
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 999px;
    color: var(--muted);
    background: rgba(255, 255, 255, .035);
    font-size: 9.5px;
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
}

.classification-confidence-badge.high {
    color: #a9e8c0;
    border-color: rgba(50, 179, 107, .35);
    background: rgba(50, 179, 107, .10);
}

.classification-confidence-badge.medium {
    color: #c7dcff;
    border-color: rgba(45, 127, 240, .35);
    background: rgba(45, 127, 240, .10);
}

.classification-confidence-badge.low {
    color: #f5c05a;
    border-color: rgba(228, 160, 43, .38);
    background: rgba(228, 160, 43, .12);
}

/* ── Nyckeltal panel ─────────────────────────────── */
#nyckeltal-panel {
    flex-shrink: 0;
    padding: 10px 10px 6px;
    border-top: 1px solid var(--line);
}

#nyckeltal-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.nyckeltal-card {
    padding: 7px 8px;
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
    min-width: 0;
}

.nyckeltal-rubrik {
    color: var(--muted);
    font-size: 9.5px;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: .08em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.nyckeltal-varde {
    color: var(--ink);
    font-size: 16px;
    font-weight: 900;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nyckeltal-kalla {
    color: var(--faint);
    font-size: 9px;
    font-weight: 650;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.trash-panel {
    flex-shrink: 0;
    padding: 8px 10px;
    border-top: 1px solid rgba(255, 255, 255, .07);
    box-shadow: inset 2px 0 0 var(--red);
}

#trash-open-btn {
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid rgba(241, 91, 80, .24);
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(241, 91, 80, .105), rgba(241, 91, 80, .035));
    color: var(--red);
    cursor: pointer;
    padding: 8px 9px;
    text-align: left;
    transition: border-color .15s, background .15s, transform .15s;
}

#trash-open-btn:hover {
    border-color: rgba(241, 91, 80, .46);
    background: linear-gradient(180deg, rgba(241, 91, 80, .15), rgba(241, 91, 80, .055));
    transform: translateY(-1px);
}

.trash-open-main {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.trash-open-title {
    color: var(--ink);
    font-size: 12px;
    font-weight: 850;
    line-height: 1.15;
}

#trash-count-label {
    color: #ffafa8;
    font-size: 10px;
    font-weight: 800;
    line-height: 1.15;
}

.trash-open-mark {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--red);
    box-shadow: 0 0 0 4px rgba(241, 91, 80, .12);
    flex-shrink: 0;
}

.no-nyckeltal {
    color: var(--faint);
    font-size: 11px;
    font-weight: 750;
    padding: 2px 8px 4px;
}

#sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--line);
}

.upload-btn {
    width: 100%;
    min-height: 38px;
    background: linear-gradient(135deg, #239653, #2fbe72);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .09);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 850;
    cursor: pointer;
    transition: transform .15s, filter .15s;
}

.upload-btn:hover { filter: brightness(1.05); transform: translateY(-1px); }

/* Chat */
#chat {
    position: relative;
    container-type: inline-size;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .025), transparent 170px),
        rgba(8, 11, 15, .88);
}

body.linkedin-mode-active #chat {
    background:
        linear-gradient(180deg, rgba(10, 102, 194, .065), transparent 210px),
        linear-gradient(135deg, rgba(45, 127, 240, .055), transparent 38%),
        rgba(8, 11, 15, .88);
}

#chat::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, .026) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .018) 1px, transparent 1px);
    background-size: 34px 34px;
    mask-image: linear-gradient(to bottom, black, transparent 58%);
}

#chat-topbar {
    position: relative;
    z-index: 1;
    min-height: 66px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(16, 22, 29, .82);
    backdrop-filter: blur(14px);
}

#workspace-controls,
.workspace-controls {
    display: none;
    align-items: center;
    gap: 4px;
    margin-right: auto;
    padding: 3px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 8px;
    background: rgba(255, 255, 255, .035);
}

.workspace-btn {
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    font-weight: 850;
    transition: background .15s, border-color .15s, color .15s;
}

.workspace-btn:hover,
.workspace-btn.active {
    background: rgba(45, 127, 240, .14);
    border-color: rgba(45, 127, 240, .34);
    color: var(--ink);
}

body.linkedin-mode-active #chat-topbar {
    box-shadow: inset 0 -1px 0 rgba(10, 102, 194, .28);
}

body.status-mode-active #chat {
    background: linear-gradient(
        160deg,
        rgba(14, 165, 233, .06) 0%,
        rgba(229, 70, 70, .03) 100%
    );
}

body.status-mode-active #chat-topbar {
    box-shadow: inset 0 -1px 0 rgba(14, 165, 233, .28);
}

.mode-toggle {
    min-height: 34px;
    padding: 0 13px;
    background: rgba(255, 255, 255, .035);
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 850;
    cursor: pointer;
    transition: background .2s, border-color .2s, color .2s, box-shadow .2s, transform .18s;
}

.mode-toggle:hover {
    background: rgba(10, 102, 194, .10);
    border-color: rgba(10, 102, 194, .42);
    color: var(--ink);
}

.mode-toggle.active {
    background: rgba(10, 102, 194, .18);
    border-color: rgba(10, 102, 194, .72);
    color: #ffffff;
    box-shadow: 0 0 0 4px rgba(10, 102, 194, .10);
}

#status-mode-btn.active {
    background: rgba(14, 165, 233, .18);
    border-color: rgba(14, 165, 233, .72);
    color: #ffffff;
    box-shadow: 0 0 0 4px rgba(14, 165, 233, .10);
}

/* ── Animated Mode Tabs ─────────────────────────────────── */
#mode-tabs {
    position: relative;
    flex: 0 0 auto;
    margin-right: auto;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, .05);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 999px;
    padding: 4px;
    gap: 0;
    user-select: none;
}

#mode-tabs-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
    overflow: hidden;
    border-radius: 999px;
    clip-path: inset(0 66% 0 0% round 20px);
    transition: clip-path 0.25s ease;
    pointer-events: none;
}

.mode-tabs-hl-track {
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
    background: rgba(45, 127, 240, 0.88);
    border-radius: 999px;
    padding: 4px;
}

.mode-tab-btn,
.mode-tab-hl {
    height: 30px;
    padding: 0 15px;
    border: none;
    background: transparent;
    font-size: 12.5px;
    font-weight: 650;
    border-radius: 999px;
    white-space: nowrap;
    letter-spacing: 0.01em;
    font-family: inherit;
}

.mode-tab-btn {
    cursor: pointer;
    color: rgba(255, 255, 255, .38);
    transition: color 0.18s;
    position: relative;
    z-index: 1;
}

.mode-tab-btn:hover {
    color: rgba(255, 255, 255, .68);
}

.mode-tab-hl {
    color: #fff;
    pointer-events: none;
    cursor: default;
}

@container (max-width: 760px) {
    #chat-topbar {
        gap: 8px;
        padding: 10px 12px;
        scrollbar-width: none;
    }

    #chat-topbar::-webkit-scrollbar {
        display: none;
    }

    #mode-tabs {
        margin-right: auto;
    }

    .mode-tab-btn,
    .mode-tab-hl {
        height: 28px;
        padding: 0 8px;
        font-size: 10.5px;
    }

    .btn-topbar,
    .tracked-chats-btn,
    .new-chat-btn {
        min-height: 32px;
        padding: 0 9px;
        font-size: 11px;
    }

    .tracked-chats-btn {
        max-width: 82px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

@container (max-width: 560px) {
    #chat-topbar {
        flex-wrap: wrap;
        align-content: center;
        overflow-x: visible;
    }

    #mode-tabs {
        width: 100%;
        margin-right: 0;
    }

    .mode-tab-btn,
    .mode-tab-hl {
        flex: 1 1 0;
        min-width: 0;
    }

    .tracked-chats-drawer {
        top: 108px;
    }
}

.new-chat-btn {
    min-height: 34px;
    padding: 0 13px;
    background: rgba(255, 255, 255, .035);
    color: var(--text);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 750;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}

.new-chat-btn:hover {
    background: rgba(255, 255, 255, .07);
    border-color: rgba(255, 255, 255, .22);
    color: #fff;
}

.tracked-chats-btn {
    min-height: 34px;
    padding: 0 13px;
    background: rgba(45, 127, 240, .12);
    color: var(--text);
    border: 1px solid rgba(45, 127, 240, .32);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 750;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}

.tracked-chats-btn:hover,
.tracked-chats-btn[aria-expanded="true"] {
    background: rgba(45, 127, 240, .18);
    border-color: rgba(45, 127, 240, .52);
    color: #fff;
    box-shadow: 0 0 0 4px rgba(45, 127, 240, .08);
}

.tracked-chats-drawer {
    position: absolute;
    top: 66px;
    right: 16px;
    z-index: 8;
    width: min(360px, calc(100vw - 32px));
    max-height: min(560px, calc(100dvh - 92px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: rgba(18, 25, 33, .96);
    box-shadow: 0 22px 70px rgba(0, 0, 0, .38);
    backdrop-filter: blur(18px);
    transform: translateY(-8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .16s, transform .16s;
}

.tracked-chats-drawer.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.tracked-chats-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 14px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.tracked-chats-label {
    color: var(--muted);
    font-size: 10px;
    font-weight: 850;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.tracked-chats-title {
    margin-top: 4px;
    color: var(--ink);
    font-size: 15px;
    font-weight: 850;
}

.tracked-chats-close {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 6px;
    background: rgba(255, 255, 255, .04);
    color: var(--muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.tracked-chats-close:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, .22);
    background: rgba(255, 255, 255, .08);
}

.tracked-chats-list {
    overflow-y: auto;
    padding: 8px;
}

.tracked-chat-item {
    width: 100%;
    min-height: 64px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 7px;
    padding: 11px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .15s;
}

.tracked-chat-item:hover,
.tracked-chat-active {
    background: rgba(255, 255, 255, .055);
    border-color: rgba(45, 127, 240, .34);
}

.tracked-chat-item:hover {
    transform: translateY(-1px);
}

.tracked-chat-title {
    color: var(--ink);
    font-size: 13px;
    font-weight: 800;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tracked-chat-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 750;
}

.tracked-chat-meta span {
    min-height: 20px;
    display: inline-flex;
    align-items: center;
    padding: 0 7px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 999px;
    background: rgba(255, 255, 255, .035);
}

.tracked-chat-active .tracked-chat-meta span:first-child {
    border-color: rgba(45, 127, 240, .42);
    color: #dcecff;
    background: rgba(45, 127, 240, .14);
}

.tracked-chats-empty {
    padding: 22px 14px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
    text-align: center;
}

.btn-topbar {
    min-height: 34px;
    padding: 0 13px;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}

.btn-topbar:hover {
    background: rgba(255, 255, 255, .05);
    border-color: var(--line-strong);
    color: var(--text);
}

#messages {
    position: relative;
    z-index: 1;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 36px 30px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-card {
    width: min(520px, 92%);
    margin: 36px auto 0;
    padding: 28px 28px 26px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(45, 127, 240, .13), transparent 38%),
        linear-gradient(315deg, rgba(50, 179, 107, .10), transparent 40%),
        rgba(21, 28, 36, .92);
    box-shadow: var(--shadow);
    text-align: center;
}

.welcome-mark {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 8px;
    background: var(--paper);
    padding: 7px;
    margin-bottom: 14px;
}

.welcome-title {
    color: var(--ink);
    font-size: 24px;
    font-weight: 900;
    letter-spacing: .01em;
}

.welcome-copy {
    color: var(--muted);
    max-width: 430px;
    margin: 9px auto 0;
    line-height: 1.55;
}

.question-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 18px;
    justify-content: center;
}

.question-chip {
    padding: 6px 13px;
    background: rgba(255, 255, 255, .042);
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 999px;
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, transform .15s;
    white-space: nowrap;
}

.question-chip:hover {
    background: rgba(45, 127, 240, .12);
    border-color: rgba(45, 127, 240, .42);
    color: #fff;
    transform: translateY(-1px);
}

.question-chip:active {
    transform: scale(.95) translateY(0);
}

.message {
    max-width: min(860px, 78%);
    border-radius: 8px;
    line-height: 1.55;
    min-width: 0;
    word-break: break-word;
    transform-origin: bottom center;
}

.message.user {
    position: relative;
    align-self: flex-end;
    padding: 11px 14px;
    background: linear-gradient(135deg, #2d7ff0, #1769d8);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .13);
    box-shadow: 0 10px 30px rgba(23, 105, 216, .23);
    border-bottom-right-radius: 2px;
    white-space: pre-wrap;
}

.message.user::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(110deg, transparent 0%, rgba(255, 255, 255, .24) 44%, transparent 64%);
    transform: translateX(-125%);
    opacity: 0;
}

.message.assistant {
    align-self: flex-start;
    width: min(640px, calc(100% - 48px));
    max-width: none;
    padding: 0;
    background: rgba(21, 28, 36, .96);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, .08);
    box-shadow: var(--shadow);
    border-bottom-left-radius: 2px;
}

.message.assistant::before {
    content: "";
    display: block;
    height: 3px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    background: linear-gradient(90deg, var(--blue), var(--green), var(--amber));
}

.assistant-content {
    min-width: 0;
    padding: 18px 20px 16px;
}

.assistant-content p {
    margin: 0 0 12px;
    color: var(--text);
    overflow-wrap: anywhere;
}

.assistant-content p:last-child { margin-bottom: 0; }

.answer-section-title {
    display: block;
    color: #fff;
    font-size: 13px;
    font-weight: 900;
    letter-spacing: .03em;
    margin: 16px 0 7px;
    text-transform: uppercase;
}

.answer-section-title:first-child { margin-top: 0; }

.assistant-content strong {
    color: #fff;
    font-weight: 900;
}

.assistant-content ul {
    list-style: none;
    margin: 0 0 12px;
    padding: 0;
}

.assistant-content li {
    position: relative;
    padding-left: 18px;
    margin: 6px 0;
    color: var(--text);
}

.assistant-content li::before {
    content: "";
    position: absolute;
    left: 1px;
    top: .68em;
    width: 7px;
    height: 7px;
    border-radius: 2px;
    background: var(--green);
    transform: rotate(45deg);
}

.assistant-citations {
    min-width: 0;
    margin-top: 16px;
    padding-top: 13px;
    border-top: 1px solid var(--line-strong);
}

.citations-title {
    color: var(--muted);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .15em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.citation-row {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: baseline;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.citation-row:last-child { border-bottom: 0; }

.citation-row[data-fil] {
    cursor: pointer;
}
.citation-row[data-fil]:hover .citation-file {
    text-decoration: underline;
}

.citation-file {
    min-width: 0;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    text-decoration: underline;
    text-decoration-color: var(--green);
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.citation-position {
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
}

.linkedin-post-card {
    min-width: 0;
    padding: 0;
    background:
        linear-gradient(135deg, rgba(10, 102, 194, .15), transparent 40%),
        rgba(21, 28, 36, .98);
    border: 1px solid rgba(10, 102, 194, .34);
    border-radius: 8px;
    overflow: hidden;
}

.linkedin-post-card::before {
    content: "";
    display: block;
    height: 3px;
    background: linear-gradient(90deg, #0a66c2, #2d7ff0, #32b36b);
}

.linkedin-post-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.linkedin-post-topline span {
    color: #dcecff;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .14em;
    text-transform: uppercase;
}

.linkedin-copy-btn {
    min-height: 30px;
    padding: 0 11px;
    border: 1px solid rgba(10, 102, 194, .42);
    border-radius: 8px;
    background: rgba(10, 102, 194, .16);
    color: #eef7ff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 850;
    transition: background .18s, border-color .18s, transform .18s;
}

.linkedin-copy-btn:hover {
    background: rgba(10, 102, 194, .26);
    border-color: rgba(10, 102, 194, .72);
    transform: translateY(-1px);
}

.linkedin-post-body {
    padding: 18px 20px 8px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.68;
    white-space: normal;
}

.linkedin-post-meta {
    padding: 0 20px 14px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
}

.linkedin-post-card .answer-diagnostics {
    padding: 0 20px 16px;
    margin-top: 0;
}

.status-report-card {
    background: var(--surface);
    border: 1px solid rgba(14, 165, 233, .28);
    border-radius: 8px;
    overflow: hidden;
    margin: 8px 0;
    position: relative;
}

.status-report-card::before {
    content: '';
    display: block;
    height: 3px;
    background: linear-gradient(90deg, var(--status-blue), var(--status-accent));
}

.status-report-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    color: var(--status-blue);
}

.status-copy-btn {
    background: rgba(14, 165, 233, .12);
    border: 1px solid rgba(14, 165, 233, .35);
    color: var(--status-blue);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background .15s;
}

.status-copy-btn:hover {
    background: rgba(14, 165, 233, .22);
}

.status-timeline-coverage {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 2px 16px 14px;
    padding: 9px 11px;
    border: 1px solid rgba(76, 175, 137, .28);
    border-radius: 8px;
    background: rgba(76, 175, 137, .08);
    color: var(--muted);
    font-size: 12px;
}

.status-timeline-coverage strong {
    color: var(--text);
    font-weight: 650;
}

.status-timeline-coverage.has-warning {
    border-color: rgba(210, 153, 34, .38);
    background: rgba(210, 153, 34, .10);
}

.status-report-body {
    padding: 0 20px 14px;
    font-size: 14px;
    line-height: 1.7;
}

.status-report-body p {
    margin: 0 0 10px;
}

.status-report-body p:last-child {
    margin-bottom: 0;
}

.status-h2 {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--status-blue);
    margin: 18px 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(14, 165, 233, .2);
}

.status-h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin: 14px 0 4px;
}

.status-divider {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, .07);
    margin: 14px 0;
}

.message.assistant:has(.status-report-card) {
    width: min(900px, calc(100% - 48px));
}

.status-report-sources {
    border-top: 1px solid rgba(14, 165, 233, .15);
    padding: 10px 16px;
    font-size: 12px;
    color: var(--muted);
    background: rgba(14, 165, 233, .04);
}

.message.system {
    align-self: center;
    padding: 6px 10px;
    background: rgba(255, 255, 255, .04);
    color: var(--muted);
    border: 1px solid rgba(255, 255, 255, .07);
    font-size: 12px;
}

.message-sent {
    animation: message-send .44s cubic-bezier(.2, .85, .22, 1) backwards;
}

.message-sent::after {
    animation: sent-glint .62s .06s ease-out both;
}

.message-received {
    animation: message-arrive .5s cubic-bezier(.18, .88, .22, 1) backwards;
}

.message-notice {
    animation: notice-arrive .34s ease backwards;
}

.message-error-motion {
    animation-duration: .42s;
}

.message-received.message-visible .assistant-content > p,
.message-received.message-visible .assistant-content > ul,
.message-received.message-visible .assistant-content > .answer-section-title,
.message-received.message-visible .assistant-citations,
.message-received.message-visible .citation-row {
    animation: answer-reveal .42s cubic-bezier(.2, .76, .25, 1) backwards;
    animation-delay: var(--reveal-delay, 0ms);
}

.message.assistant.error {
    background: rgba(67, 24, 24, .96);
    color: #ffd2cd;
}

.message.loading {
    align-self: flex-start;
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 11px;
    align-items: center;
    width: min(286px, calc(100% - 48px));
    min-width: 238px;
    min-height: 64px;
    padding: 13px 15px 15px;
    background: rgba(21, 28, 36, .96);
    border: 1px solid rgba(255, 255, 255, .08);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: message-arrive .36s cubic-bezier(.18, .88, .22, 1) backwards;
}

.thinking-pulse {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(45, 127, 240, .12);
    box-shadow: inset 0 0 0 1px rgba(45, 127, 240, .24);
}

.thinking-pulse span {
    --dot-x: 0px;
    grid-area: 1 / 1;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9dbdff;
    box-shadow: 0 0 12px rgba(45, 127, 240, .64);
    animation: thinking-dot 1.05s infinite;
}

.thinking-pulse span:nth-child(1) { --dot-x: -8px; }
.thinking-pulse span:nth-child(2) { animation-delay: .14s; }
.thinking-pulse span:nth-child(3) { --dot-x: 8px; animation-delay: .28s; }

.thinking-copy {
    min-width: 0;
    white-space: nowrap;
    color: var(--ink);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .01em;
}

.shining-text {
    display: inline-block;
    max-width: 100%;
    background: linear-gradient(110deg, #9fb0bc, 35%, #ffffff, 50%, #9fb0bc, 75%, #9fb0bc);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: shining-text 2s linear infinite;
}

.thinking-label-pop {
    animation: thinking-label-pop .24s ease both;
}

.thinking-dots::after {
    content: "...";
    display: inline-block;
    width: 18px;
    overflow: hidden;
    text-align: left;
    vertical-align: bottom;
    animation: thinking-ellipsis 1.1s steps(4, end) infinite;
}

.thinking-scan {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background:
        linear-gradient(90deg, transparent, rgba(45, 127, 240, .96), rgba(50, 179, 107, .92), transparent);
    transform: translateX(-100%);
    animation: thinking-scan 1.45s cubic-bezier(.42, 0, .2, 1) infinite;
}

@keyframes message-send {
    0% { opacity: 0; transform: translate(14px, 12px) scale(.98); filter: saturate(.85); }
    62% { opacity: 1; transform: translate(-1px, -1px) scale(1.012); filter: saturate(1.08); }
    100% { opacity: 1; transform: none; filter: none; }
}

@keyframes sent-glint {
    0% { opacity: 0; transform: translateX(-125%); }
    22% { opacity: 1; }
    100% { opacity: 0; transform: translateX(125%); }
}

@keyframes message-arrive {
    0% { opacity: 0; transform: translate(-12px, 16px); }
    70% { opacity: 1; transform: translate(1px, -1px); }
    100% { opacity: 1; transform: none; }
}

@keyframes notice-arrive {
    from { opacity: 0; transform: translateY(7px); }
    to { opacity: 1; transform: none; }
}

@keyframes answer-reveal {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}

@keyframes thinking-dot {
    0%, 70%, 100% { opacity: .42; transform: translate(var(--dot-x), 0) scale(.82); }
    34% { opacity: 1; transform: translate(var(--dot-x), -4px) scale(1); }
}

@keyframes thinking-label-pop {
    from { opacity: .58; transform: translateY(3px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes thinking-ellipsis {
    0% { width: 0; }
    100% { width: 18px; }
}

@keyframes thinking-scan {
    0% { transform: translateX(-100%); opacity: 0; }
    18% { opacity: 1; }
    82% { opacity: 1; }
    100% { transform: translateX(100%); opacity: 0; }
}

@keyframes shining-text {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

#input-area {
    position: relative;
    z-index: 1;
    padding: 14px 18px;
    border-top: 1px solid var(--line);
    background: rgba(16, 22, 29, .91);
    backdrop-filter: blur(14px);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: rgba(255, 255, 255, .045);
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    padding: 8px 8px 8px 14px;
    transition: border-color .15s, background .15s, box-shadow .15s;
}

.input-box:focus-within {
    border-color: rgba(45, 127, 240, .85);
    background: rgba(255, 255, 255, .06);
    box-shadow: 0 0 0 4px rgba(45, 127, 240, .12);
}

#message-input {
    flex: 1;
    min-height: 38px;
    max-height: 128px;
    padding: 6px 0;
    resize: none;
    outline: none;
    background: transparent;
    border: none;
    color: var(--ink);
    line-height: 1.5;
}

#message-input::placeholder { color: var(--muted); }

#send-btn {
    position: relative;
    overflow: hidden;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #2d7ff0, #32b36b);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform .15s, filter .15s, opacity .15s;
}

#send-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
#send-btn:disabled {
    cursor: not-allowed;
    transform: none;
    animation: send-btn-breathe 1.6s ease-in-out infinite;
}

@keyframes send-btn-breathe {
    0%, 100% { opacity: .46; filter: brightness(1); }
    50%       { opacity: .72; filter: brightness(1.14); }
}

#send-btn.is-sending {
    animation: send-button-press .42s cubic-bezier(.2, .85, .22, 1) both;
}

@keyframes send-button-press {
    0% { transform: scale(1); }
    44% { transform: scale(.9); filter: brightness(1.16); }
    100% { transform: scale(1); filter: brightness(1); }
}

.btn-ripple {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(255, 255, 255, .30);
    transform: scale(0);
    animation: btn-ripple .52s cubic-bezier(.2, .75, .2, 1) forwards;
    pointer-events: none;
}

@keyframes btn-ripple {
    to { transform: scale(2.4); opacity: 0; }
}

.conversation-history {
    font-size: 0.78rem;
    color: var(--muted);
    padding: 2px 0;
    min-height: 0;
}
.conversation-history .turn-count {
    display: inline-block;
    background: rgba(45, 127, 240, .13);
    border-radius: 4px;
    padding: 2px 8px;
}

.answer-diagnostics {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 0.74rem;
}

.answer-diagnostics span {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 0 8px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 6px;
    background: rgba(255, 255, 255, .035);
}

.btn-secondary {
    padding: 9px 12px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .045);
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: color .15s, background .15s;
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, .09);
    color: var(--text);
}

/* Sources */
#sources {
    border-left: 1px solid var(--line);
    padding: 16px 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.no-sources {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
    text-align: center;
    margin-top: 22px;
}

.source-group {
    --source-accent: var(--blue);
    --source-tint: rgba(45, 127, 240, .12);
    border-left: 3px solid var(--source-accent);
    border-radius: 8px;
    background: linear-gradient(90deg, var(--source-tint), rgba(27, 36, 46, .94) 42%);
    box-shadow: inset 0 0 0 1px rgba(240, 246, 252, .04);
    overflow: hidden;
}

.source-group + .source-group { margin-top: 8px; }

.source-summary {
    width: 100%;
    min-height: 58px;
    border: 0;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr) 12px;
    align-items: center;
    gap: 8px;
    padding: 9px 9px 9px 8px;
    text-align: left;
}

.source-summary:hover { background: rgba(240, 246, 252, .045); }

.source-color-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--source-accent);
    box-shadow: 0 0 13px var(--source-accent);
}

.source-summary-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.source-name {
    color: var(--ink);
    font-size: 12px;
    font-weight: 850;
    line-height: 1.24;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.source-meta {
    color: var(--muted);
    font-size: 10.5px;
    line-height: 1.35;
}

.source-chevron {
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: rotate(45deg);
    transition: transform .22s ease, border-color .15s;
}

.source-group.open .source-chevron {
    transform: translateY(3px) rotate(225deg);
    border-color: var(--source-accent);
}

.source-details {
    position: relative;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    padding: 0 8px;
    transition: max-height .34s cubic-bezier(.2, .75, .2, 1), opacity .18s ease, padding .25s ease;
}

.source-details.open {
    max-height: 900px;
    opacity: 1;
    pointer-events: auto;
    padding: 0 8px 8px;
}

.source-hit {
    width: 100%;
    border: 1px solid rgba(240, 246, 252, .07);
    border-left: 2px solid var(--source-accent);
    border-radius: 6px;
    background: rgba(8, 11, 15, .36);
    color: var(--text);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
    padding: 9px 10px;
    text-align: left;
    transform-origin: top;
    animation: source-hit-drop .28s ease both;
    animation-delay: var(--hit-delay, 0ms);
    transition: border-color .15s, background .15s;
}

.source-hit:hover {
    border-color: color-mix(in srgb, var(--source-accent) 56%, transparent);
    background: rgba(240, 246, 252, .052);
}

.source-hit-primary {
    background: rgba(8, 11, 15, .46);
    border-left-width: 3px;
}

.source-context-list {
    margin-left: 8px;
    padding-left: 10px;
    border-left: 1px solid rgba(240, 246, 252, .08);
}

.source-hit-context {
    border-left-color: rgba(157, 171, 182, .58);
    background: rgba(8, 11, 15, .24);
    opacity: .86;
}

.source-hit-context:hover {
    border-left-color: rgba(157, 171, 182, .76);
    background: rgba(240, 246, 252, .04);
    opacity: .96;
}

.source-hit-nested {
    margin-top: 5px;
}

.source-hit-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: baseline;
}

.source-hit-position {
    color: var(--ink);
    font-size: 11px;
    font-weight: 850;
    margin-right: auto;
}

.source-hit-role {
    color: var(--muted);
    border: 1px solid rgba(240, 246, 252, .09);
    border-radius: 999px;
    background: rgba(240, 246, 252, .045);
    padding: 1px 6px;
    font-size: 9.5px;
    font-weight: 800;
    line-height: 1.5;
}

.source-hit-score {
    color: var(--source-accent);
    font-size: 11px;
    font-weight: 900;
    flex-shrink: 0;
}

.source-hit-excerpt {
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.52;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    transition: color .15s;
}

.source-hit.expanded .source-hit-excerpt {
    max-height: 320px;
    color: #c4d2da;
    display: block;
    -webkit-line-clamp: unset;
    overflow-y: auto;
}

.source-hit-open {
    display: none;
    margin-top: 7px;
    font-size: 11px;
    font-weight: 800;
    color: var(--source-accent);
    letter-spacing: .02em;
    cursor: pointer;
}

.source-hit-open:hover { text-decoration: underline; }

.source-hit.expanded .source-hit-open { display: block; }

@keyframes source-hit-drop {
    from { opacity: 0; transform: translateY(-6px) scaleY(.96); }
    to { opacity: 1; transform: translateY(0) scaleY(1); }
}

/* Tablet landscape (iPad Air/Pro): all 3 panels, compact sizes */
@media (max-width: 1200px) {
    #workspace-controls,
    .workspace-controls {
        display: flex;
    }

    #app {
        grid-template-columns:
            min(var(--sidebar-w, 196px), 210px) 10px
            minmax(260px, 1fr) 10px
            min(var(--sources-w, 290px), 310px);
    }

    .resize-handle { min-width: 10px; }

    .message { max-width: min(820px, 88%); }
    .message.assistant { width: min(580px, calc(100% - 32px)); }
    .message.assistant:has(.status-report-card) { width: min(820px, calc(100% - 32px)); }
}

/* Tablet portrait / small tablet: chat first, panels remain reachable */
@media (max-width: 860px) {
    #app { grid-template-columns: 0 0 minmax(0, 1fr) 0 0; }
    #sidebar,
    #sources {
        position: absolute;
        top: var(--safe-top);
        bottom: var(--safe-bottom);
        z-index: 30;
        width: min(340px, calc(100vw - 28px));
        max-width: calc(100vw - 28px);
        display: flex;
        transition: transform .22s ease, box-shadow .22s ease;
    }
    #sidebar {
        left: var(--safe-left);
        transform: translateX(calc(-100% - 18px));
        border-right: 1px solid var(--line);
    }
    #sources {
        right: var(--safe-right);
        transform: translateX(calc(100% + 18px));
        border-left: 1px solid var(--line);
    }
    body[data-workspace-mode="library"] #sidebar {
        transform: translateX(0);
        box-shadow: 22px 0 60px rgba(0, 0, 0, .38);
    }
    body[data-workspace-mode="sources"] #sources {
        transform: translateX(0);
        box-shadow: -22px 0 60px rgba(0, 0, 0, .38);
    }
    #resize-right { display: none; }
    #resize-left { display: none; }
    #chat-topbar {
        z-index: 40;
        gap: 8px;
        padding: 10px 12px;
    }
    #mode-tabs {
        margin-right: 8px;
    }
    .mode-tab-btn,
    .mode-tab-hl {
        padding: 0 11px;
        font-size: 11.5px;
    }
    #workspace-controls,
    .workspace-controls { flex: 1; }
    .workspace-btn {
        flex: 1;
        padding: 0 7px;
    }
    .message { max-width: min(820px, 88%); }
    .message.assistant { width: min(640px, calc(100% - 32px)); }
}

@media (pointer: coarse) {
    button,
    .folder-header,
    .doc-item,
    .source-summary,
    .source-hit,
    .research-citation-summary {
        min-height: 44px;
    }

    .resize-handle {
        min-width: 14px;
    }

    .folder-inline-actions {
        opacity: 1;
        pointer-events: auto;
    }

    .folder-control-btn {
        width: 34px;
        height: 34px;
    }
}

/* Phone */
@media (max-width: 760px) {
    #app { grid-template-columns: 1fr; }
    #chat {
        grid-column: 1;
        grid-row: 1;
    }
    #chat-topbar { padding: 10px 12px; }
    .tracked-chats-btn {
        max-width: 118px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .tracked-chats-drawer {
        top: 62px;
        right: 10px;
        width: calc(100vw - 20px);
    }
    #messages { padding: 20px 12px; }
    .message { max-width: 94%; }
    .message.assistant,
    .message.loading {
        width: 100%;
        min-width: 0;
    }
    #input-area { padding: 10px 12px; }
}

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

    .thinking-scan { opacity: .7; transform: none; }
    .shining-text { color: var(--ink); background: none; }
}

::-webkit-scrollbar { width: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #34424d; border-radius: 999px; }

/* Login screen */
#login-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        linear-gradient(135deg, rgba(45, 127, 240, .11), transparent 28%),
        linear-gradient(315deg, rgba(50, 179, 107, .08), transparent 31%),
        var(--bg);
}
#login-screen.hidden { display: none; }

.login-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 40px 36px;
    width: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    box-shadow: var(--shadow);
}
.login-mark { width: 38px; height: 38px; margin-bottom: 6px; }
.login-title { font-size: 17px; font-weight: 600; color: var(--ink); }
.login-subtitle { font-size: 12px; color: var(--muted); margin-bottom: 18px; }

#login-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#login-email,
#login-password,
#login-totp {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--ink);
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
    box-sizing: border-box;
}
#login-email:focus,
#login-password:focus,
#login-totp:focus { border-color: var(--blue); }
#login-email::placeholder,
#login-password::placeholder,
#login-totp::placeholder { color: var(--faint); }
.login-mfa-step.hidden { display: none; }

#login-btn {
    width: 100%;
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
}
#login-btn:hover { opacity: .88; }
#login-btn:active { opacity: .72; }
#login-btn:disabled { opacity: .5; cursor: default; }

.login-error {
    font-size: 12px;
    color: var(--red);
    min-height: 18px;
    text-align: center;
    margin-top: 2px;
}

/* ── MFA setup modal ─────────────────────────────────────────────── */
.mfa-instruction {
    font-size: 13px;
    color: var(--muted);
    margin: 0 0 14px;
    line-height: 1.5;
}
.mfa-qr-wrap {
    display: flex;
    justify-content: center;
    margin: 4px 0 6px;
}
.mfa-qr-image {
    width: 180px;
    height: 180px;
    border-radius: 8px;
    background: #fff;
    padding: 6px;
    box-sizing: border-box;
}
.mfa-secret-code {
    font-family: monospace;
    font-size: 13px;
    letter-spacing: .08em;
    color: var(--text);
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 6px;
    padding: 8px 12px;
    word-break: break-all;
    user-select: all;
}
.mfa-success-msg {
    font-size: 14px;
    color: var(--green, #3fb950);
    line-height: 1.6;
    padding: 12px 0 4px;
}

/* ── Folder tree ─────────────────────────────────────────────────── */
.folder-section-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 9px;
}
.select-all-btn {
    min-width: 44px;
    background: rgba(255, 255, 255, .035);
    border: 1px solid rgba(255, 255, 255, .10);
    color: var(--muted);
    border-radius: 8px;
    font-size: 10px;
    font-weight: 850;
    padding: 4px 8px;
    cursor: pointer;
    line-height: 1.15;
    transition: background .15s, border-color .15s, color .15s, transform .15s;
}
.select-all-btn:hover {
    background: rgba(45, 127, 240, .10);
    border-color: rgba(45, 127, 240, .42);
    color: var(--ink);
    transform: translateY(-1px);
}
.folder-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.folder-action-btn {
    background: rgba(255, 255, 255, .035);
    border: 1px solid rgba(255, 255, 255, .10);
    color: var(--muted);
    border-radius: 8px;
    font-size: 10px;
    font-weight: 850;
    padding: 4px 8px;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, transform .15s;
}
.folder-action-btn:hover {
    background: rgba(45, 127, 240, .10);
    border-color: rgba(45, 127, 240, .42);
    color: var(--ink);
}
#folder-tree {
    display: grid;
    gap: 7px;
}
.folder-item {
    overflow: hidden;
    margin-bottom: 0;
    border: 1px solid rgba(255, 255, 255, .075);
    border-radius: 8px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .035), rgba(255, 255, 255, .015)),
        rgba(12, 17, 23, .74);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035);
    transition: border-color .15s, background .15s, box-shadow .15s;
}
.folder-item:hover {
    border-color: rgba(255, 255, 255, .13);
}
.folder-item:not(.collapsed) {
    border-color: rgba(45, 127, 240, .30);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .045), 0 8px 22px rgba(0, 0, 0, .16);
}
.folder-header {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 8px 9px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    transition: background .12s;
}
.folder-header:hover {
    background: rgba(255, 255, 255, .04);
}
.folder-header:focus-visible {
    outline: 2px solid rgba(45, 127, 240, .58);
    outline-offset: -2px;
}
.folder-checkbox {
    appearance: none;
    position: relative;
    width: 16px;
    height: 16px;
    border: 1px solid rgba(142, 160, 170, .58);
    border-radius: 5px;
    background: rgba(255, 255, 255, .035);
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, border-color .15s, box-shadow .15s;
}
.folder-checkbox:hover {
    border-color: rgba(214, 224, 230, .82);
}
.folder-checkbox:checked {
    background: linear-gradient(135deg, #2d7ff0, #32b36b);
    border-color: transparent;
    box-shadow: 0 0 0 3px rgba(45, 127, 240, .14);
}
.folder-checkbox:checked::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 45%;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: translate(-50%, -50%) rotate(45deg);
}
.folder-chevron {
    margin-left: auto;
    position: relative;
    width: 18px;
    height: 18px;
    border-radius: 6px;
    background: rgba(255, 255, 255, .035);
    color: var(--muted);
    flex-shrink: 0;
    transition: background .15s, transform .15s;
}
.folder-chevron::before {
    content: "";
    position: absolute;
    left: 6px;
    top: 5px;
    width: 6px;
    height: 6px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    transition: transform .15s, top .15s;
}
.folder-item.collapsed .folder-chevron::before {
    top: 6px;
    transform: rotate(-45deg);
}
.folder-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.folder-doc-count {
    font-size: 10px;
    color: var(--muted);
    font-weight: 750;
    padding: 2px 6px;
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 999px;
    background: rgba(255, 255, 255, .03);
    flex-shrink: 0;
}
.folder-inline-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .12s;
}
.folder-header:hover .folder-inline-actions,
.folder-header:focus-within .folder-inline-actions {
    opacity: 1;
    pointer-events: auto;
}
.folder-control-btn {
    width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .10);
    border-radius: 6px;
    background: rgba(255, 255, 255, .035);
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
}
.folder-control-btn:hover {
    border-color: rgba(45, 127, 240, .45);
    color: var(--ink);
    background: rgba(45, 127, 240, .10);
}
.folder-docs {
    display: grid;
    gap: 5px;
    padding: 7px 7px 8px 10px;
    border-top: 1px solid rgba(255, 255, 255, .07);
    background: rgba(0, 0, 0, .12);
}
.folder-docs .doc-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
    padding: 8px 9px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .018);
}
.doc-main {
    display: block;
    min-width: 0;
    flex: 1;
}

.folder-item.collapsed .folder-docs {
    display: none;
}

/* ── Modals ─────────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(3, 7, 12, .62);
}
.app-modal {
    position: fixed;
    z-index: 41;
    top: 50%;
    left: 50%;
    width: min(420px, calc(100vw - 32px));
    transform: translate(-50%, -50%);
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 12px;
    background: #111820;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .42);
    padding: 18px;
}
.app-modal.hidden,
.modal-backdrop.hidden {
    display: none;
}
.app-modal h2 {
    margin: 0 0 14px;
    font-size: 16px;
}
.field-label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}
.field-control {
    width: 100%;
    min-height: 38px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 8px;
    background: rgba(255, 255, 255, .04);
    color: var(--text);
    padding: 8px 10px;
    box-sizing: border-box;
}
.modal-context {
    margin: 0 0 14px;
    color: var(--text);
    font-size: 13px;
    overflow-wrap: anywhere;
}
.modal-error {
    min-height: 18px;
    margin-top: 8px;
    color: var(--red, #f85149);
    font-size: 12px;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}
.btn-primary {
    border: 0;
    border-radius: 8px;
    background: linear-gradient(135deg, #2d7ff0, #32b36b);
    color: #fff;
    font-weight: 850;
    padding: 9px 12px;
    cursor: pointer;
    font-size: 13px;
}
.btn-primary:disabled,
.btn-secondary:disabled {
    opacity: .55;
    cursor: default;
}
.btn-danger {
    background: linear-gradient(135deg, #d93d42, #b4212a);
}

#document-trash-modal.trash-modal {
    width: min(620px, calc(100vw - 32px));
    max-height: min(680px, calc(100dvh - 32px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#document-trash-modal.trash-modal.hidden {
    display: none;
}

.trash-modal-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.trash-modal-header h2 {
    margin: 0;
}

.trash-modal-kicker {
    color: #ffafa8;
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
}

.trash-tabs,
.trash-mode-toggle {
    display: flex;
    gap: 6px;
    padding: 3px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 8px;
    background: rgba(255, 255, 255, .035);
}

.trash-tabs {
    margin-bottom: 12px;
}

.trash-mode-toggle {
    width: fit-content;
    margin-bottom: 10px;
}

.trash-tab,
.trash-mode-btn {
    min-height: 30px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 850;
    padding: 0 11px;
}

.trash-tab.active,
.trash-mode-btn.active {
    background: rgba(241, 91, 80, .15);
    color: var(--ink);
    box-shadow: inset 0 0 0 1px rgba(241, 91, 80, .28);
}

.trash-tab-panel.hidden,
.trash-list.hidden {
    display: none;
}

.trash-list {
    display: grid;
    gap: 7px;
    max-height: min(42vh, 360px);
    overflow-y: auto;
    padding: 2px;
    scrollbar-gutter: stable;
}

.trash-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, .085);
    border-radius: 8px;
    background: rgba(255, 255, 255, .026);
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.trash-row:hover {
    border-color: rgba(241, 91, 80, .34);
    background: rgba(241, 91, 80, .055);
}

.trash-row.is-disabled {
    cursor: default;
    opacity: .54;
}

.trash-row.is-disabled:hover {
    border-color: rgba(255, 255, 255, .085);
    background: rgba(255, 255, 255, .026);
}

.trash-checkbox {
    width: 16px;
    height: 16px;
    margin-top: 2px;
    accent-color: var(--red);
    flex-shrink: 0;
}

.trash-row-main {
    display: grid;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

.trash-row-main strong {
    color: var(--ink);
    font-size: 12.5px;
    font-weight: 820;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.trash-row-main span,
.trash-empty {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
}

.trash-empty {
    padding: 12px 4px;
}

@media (max-width: 760px) {
    #document-trash-modal.trash-modal {
        width: calc(100vw - 20px);
        max-height: calc(100dvh - 20px);
        padding: 14px;
    }
    .trash-modal-header {
        display: grid;
        gap: 4px;
    }
    .trash-modal-kicker {
        white-space: normal;
    }
    .trash-mode-toggle {
        width: 100%;
    }
    .trash-mode-btn,
    .trash-tab {
        flex: 1;
    }
    .trash-list {
        max-height: 46dvh;
    }
}

::-webkit-scrollbar-thumb:hover { background: #465663; }

/* Research sources panel */
.research-section-label {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

#research-sources-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 16px;
}

.research-citation {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-left: 2px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    transition: background .15s, border-color .15s, box-shadow .15s;
}

.research-citation:hover,
.research-citation.open {
    background: rgba(240, 246, 252, .052);
    border-left-color: var(--green);
    box-shadow: inset 0 0 0 1px rgba(240, 246, 252, .035);
}

.research-citation-summary {
    width: 100%;
    min-height: 58px;
    border: 0;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 12px;
    align-items: center;
    gap: 8px;
    padding: 10px 11px;
    text-align: left;
}

.research-citation-summary:focus-visible {
    outline: 1px solid rgba(126, 231, 135, .72);
    outline-offset: -2px;
}

.research-citation-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.research-citation-text {
    font-size: 11.5px;
    line-height: 1.45;
    color: rgba(255, 255, 255, 0.82);
    word-break: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.research-citation-source {
    font-size: 10.5px;
    color: rgba(255, 255, 255, 0.38);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.research-chevron {
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: rotate(45deg);
    transition: transform .22s ease, border-color .15s;
}

.research-citation.open .research-chevron {
    transform: translateY(3px) rotate(225deg);
    border-color: var(--green);
}

.research-citation-detail {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    padding: 0 11px;
    transition: max-height .32s cubic-bezier(.2, .75, .2, 1), opacity .18s ease, padding .24s ease;
}

.research-citation.open .research-citation-detail {
    max-height: 520px;
    opacity: 1;
    overflow-y: auto;
    pointer-events: auto;
    padding: 0 11px 11px;
}

.research-detail-label {
    border-top: 1px solid rgba(255, 255, 255, .07);
    color: rgba(157, 171, 182, .78);
    font-size: 9.5px;
    font-weight: 850;
    letter-spacing: .04em;
    margin-top: 8px;
    padding-top: 8px;
    text-transform: uppercase;
}

.research-detail-text,
.research-detail-excerpt {
    color: #c4d2da;
    font-size: 11.5px;
    line-height: 1.5;
    margin-top: 5px;
    max-height: 140px;
    overflow-y: auto;
    overflow-wrap: anywhere;
}

.research-detail-excerpt {
    color: var(--muted);
    max-height: 96px;
    overflow-y: auto;
}

.research-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin-top: 8px;
}

.research-detail-grid div {
    min-width: 0;
    border: 1px solid rgba(240, 246, 252, .07);
    border-radius: 6px;
    background: rgba(8, 11, 15, .28);
    color: rgba(240, 246, 252, .78);
    font-size: 10.5px;
    line-height: 1.35;
    padding: 6px 7px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.research-detail-grid span {
    display: block;
    color: rgba(157, 171, 182, .62);
    font-size: 9px;
    font-weight: 850;
    margin-bottom: 2px;
    text-transform: uppercase;
}

.research-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.research-action-btn {
    min-height: 28px;
    border: 1px solid rgba(240, 246, 252, .10);
    border-radius: 6px;
    background: rgba(240, 246, 252, .045);
    color: rgba(240, 246, 252, .78);
    cursor: pointer;
    font-size: 10.5px;
    font-weight: 850;
    padding: 5px 8px;
    transition: border-color .15s, background .15s, color .15s;
}

.research-action-btn:hover {
    border-color: rgba(126, 231, 135, .32);
    background: rgba(126, 231, 135, .10);
    color: var(--ink);
}

.research-action-btn.copied,
.research-action-primary {
    border-color: rgba(126, 231, 135, .26);
    color: var(--green);
}

/* ── Context menu ─────────────────────────────── */
.context-menu {
    position: fixed;
    z-index: 9999;
    min-width: 160px;
    background: var(--surface-2);
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .55);
    padding: 4px 0;
    user-select: none;
}
.context-menu.hidden {
    display: none;
}
.context-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    border-radius: 4px;
    margin: 0 4px;
    position: relative;
    transition: background .12s, color .12s;
}
.context-menu-item:hover {
    background: rgba(45, 127, 240, .15);
    color: var(--ink);
}
.context-menu-item--submenu:hover > .context-submenu {
    display: block;
}
.context-menu-arrow {
    color: var(--muted);
    font-size: 15px;
    line-height: 1;
}
.context-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: -4px;
    min-width: 160px;
    background: var(--surface-2);
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .55);
    padding: 4px 0;
    z-index: 10000;
}
.context-submenu.submenu-left {
    left: auto;
    right: 100%;
}
.context-submenu-item {
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    border-radius: 4px;
    margin: 0 4px;
    transition: background .12s, color .12s;
    white-space: nowrap;
}
.context-submenu-item:hover {
    background: rgba(45, 127, 240, .15);
    color: var(--ink);
}
.context-submenu-item.disabled {
    opacity: .45;
    cursor: default;
    pointer-events: none;
}

/* ── Loading Screen ──────────────────────────────────────────── */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(160deg, #0d1520 0%, #0a1428 55%, #080f1a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
#loading-screen.hidden {
  display: none;
}
#loading-screen.loading-fade-out {
  animation: loadingFadeOut 0.6s ease forwards;
}
#loading-screen::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(45, 127, 240, 0.10) 0%, transparent 65%);
  top: -150px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}
.loading-card {
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 20px;
  padding: 60px 72px 52px;
  text-align: center;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: relative;
  z-index: 1;
  animation: loadingCardIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.loading-welcome {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.5px;
  line-height: 1.2;
  margin-bottom: 10px;
  animation: loadingItemUp 0.55s ease 0.10s both;
}
.loading-ready {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 32px;
  animation: loadingItemUp 0.55s ease 0.22s both;
}
.loading-spinner-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 30px;
  animation: loadingItemUp 0.55s ease 0.32s both;
}
.loading-spinner {
  width: 26px;
  height: 26px;
  border: 2px solid rgba(45, 127, 240, 0.18);
  border-top: 2px solid var(--blue);
  border-radius: 50%;
  animation: loadingSpin 0.85s linear infinite;
}
.loading-cta {
  font-size: 12px;
  color: var(--muted);
  animation: loadingItemUp 0.55s ease 0.40s both;
}
@keyframes loadingFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes loadingFadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}
@keyframes loadingCardIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes loadingItemUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes loadingSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ── Extern analys ───────────────────────────────────────────────────────── */
#mode-engagement-copilot {
    display: none;
}

body.engagement-copilot-mode-active #app {
    grid-template-columns: minmax(0, 1fr);
}

body.engagement-copilot-mode-active #chat {
    grid-column: 1;
}

body.engagement-copilot-mode-active #sidebar,
body.engagement-copilot-mode-active #sources,
body.engagement-copilot-mode-active #resize-left,
body.engagement-copilot-mode-active #resize-right {
    display: none;
}

body.engagement-copilot-mode-active #messages,
body.engagement-copilot-mode-active #input-area {
    display: none;
}

body.engagement-copilot-mode-active #mode-engagement-copilot {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px clamp(18px, 3vw, 38px) 34px;
    background:
        linear-gradient(180deg, rgba(50, 179, 107, .08), transparent 230px),
        rgba(8, 11, 15, .72);
}

.engagement-shell {
    width: min(1480px, 100%);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.engagement-head,
.engagement-summary-band {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
    border: 1px solid rgba(255, 255, 255, .09);
    border-radius: 8px;
    background: rgba(16, 22, 29, .88);
    box-shadow: 0 18px 42px rgba(0, 0, 0, .2);
}

.engagement-kicker {
    display: block;
    color: var(--green);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .14em;
    line-height: 1;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.engagement-title,
.engagement-summary-band h3 {
    color: var(--ink);
    font-size: clamp(24px, 3vw, 38px);
    font-weight: 900;
    line-height: 1.02;
}

.engagement-summary-band h3 {
    font-size: 24px;
}

.engagement-sub,
.engagement-summary-band p {
    max-width: 820px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
    margin-top: 8px;
}

.engagement-ghost-btn,
.engagement-primary-btn {
    min-height: 38px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 8px;
    padding: 0 13px;
    color: var(--ink);
    background: rgba(255, 255, 255, .045);
    cursor: pointer;
    font-size: 12px;
    font-weight: 850;
    white-space: nowrap;
}

.engagement-primary-btn {
    border-color: rgba(50, 179, 107, .42);
    background: rgba(50, 179, 107, .15);
}

.engagement-ghost-btn:hover,
.engagement-primary-btn:hover,
.engagement-scope-card:hover,
.engagement-folder-row:hover {
    border-color: rgba(50, 179, 107, .46);
    background: rgba(50, 179, 107, .09);
}

.engagement-status {
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, .09);
    border-radius: 8px;
    color: var(--muted);
    background: rgba(255, 255, 255, .035);
    font-size: 12px;
    font-weight: 750;
}

.engagement-status[data-tone="ok"] {
    color: #9ce0ba;
    border-color: rgba(50, 179, 107, .28);
}

.engagement-status[data-tone="warn"] {
    color: #f1c574;
    border-color: rgba(228, 160, 43, .3);
}

.engagement-status[data-tone="error"] {
    color: #ffa29c;
    border-color: rgba(241, 91, 80, .3);
}

.engagement-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 2px 0 10px;
}

.engagement-section-head h3 {
    color: var(--ink);
    font-size: 13px;
    font-weight: 900;
    text-transform: uppercase;
}

.engagement-section-head span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
}

.engagement-scope-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 10px;
}

.engagement-scope-card,
.engagement-folder-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-height: 112px;
    padding: 13px;
    border: 1px solid rgba(255, 255, 255, .09);
    border-radius: 8px;
    color: var(--text);
    background: rgba(16, 22, 29, .76);
    cursor: pointer;
    text-align: left;
    transition: border-color .15s, background .15s, transform .15s;
}

.engagement-scope-card.is-global {
    border-color: rgba(255, 255, 255, .09);
    background: rgba(16, 22, 29, .76);
}

.engagement-scope-card.is-active,
.engagement-scope-card.is-active:hover,
.engagement-scope-card:focus,
.engagement-scope-card:focus-visible {
    outline: none;
    border-color: rgba(50, 179, 107, .58);
    background: rgba(50, 179, 107, .09);
    box-shadow: inset 0 0 0 1px rgba(50, 179, 107, .22);
}

.engagement-scope-card strong,
.engagement-folder-row strong {
    color: var(--ink);
    font-size: 17px;
    line-height: 1.15;
    margin: 6px 0;
    overflow-wrap: anywhere;
}

.engagement-scope-eyebrow,
.engagement-scope-meta,
.engagement-scope-date,
.engagement-folder-row span,
.engagement-folder-row em {
    color: var(--muted);
    font-size: 11px;
    font-style: normal;
    font-weight: 750;
    line-height: 1.35;
}

.engagement-scope-eyebrow {
    color: var(--green);
    font-size: 10px;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.engagement-detail {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.engagement-band-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(94px, 1fr));
    gap: 8px;
    min-width: 260px;
}

.engagement-band-metrics span {
    min-height: 56px;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 8px;
    color: var(--muted);
    background: rgba(255, 255, 255, .035);
    font-size: 11px;
    font-weight: 750;
}

.engagement-band-metrics strong {
    display: block;
    color: var(--ink);
    font-size: 22px;
    line-height: 1;
    margin-bottom: 5px;
}

.engagement-action-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
}

.engagement-dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 12px;
}

.engagement-panel {
    grid-column: span 4;
    min-height: 190px;
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, .09);
    border-radius: 8px;
    background: rgba(16, 22, 29, .8);
}

.engagement-since-last,
.engagement-imgd-panel,
.engagement-timeline-panel {
    grid-column: span 4;
}

.engagement-figures-panel,
.engagement-actions-panel,
.engagement-risks-panel,
.engagement-next-panel,
.engagement-notes-panel {
    grid-column: span 3;
}

.engagement-panel h3 {
    color: var(--ink);
    font-size: 13px;
    font-weight: 900;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.engagement-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-left: 16px;
}

.engagement-list li,
.engagement-empty,
.engagement-loading,
.engagement-error {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.engagement-error {
    color: #ffa29c;
}

.engagement-figure,
.engagement-stage,
.engagement-timeline-row,
.engagement-event {
    display: grid;
    gap: 4px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.engagement-figure:last-child,
.engagement-stage:last-child,
.engagement-timeline-row:last-child,
.engagement-event:last-child {
    border-bottom: 0;
}

.engagement-figure span,
.engagement-stage span,
.engagement-timeline-row time,
.engagement-event span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
}

.engagement-figure strong,
.engagement-stage strong,
.engagement-timeline-row strong {
    color: var(--ink);
    font-size: 13px;
    line-height: 1.35;
}

.engagement-timeline-row {
    grid-template-columns: 82px minmax(0, 1fr);
}

.engagement-timeline-row span,
.engagement-event p {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.engagement-folder-row {
    width: 100%;
    min-height: 86px;
    margin-bottom: 8px;
}

.engagement-notes-panel textarea {
    width: 100%;
    min-height: 86px;
    margin: 12px 0 8px;
    padding: 10px;
    resize: vertical;
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 8px;
    color: var(--ink);
    background: rgba(0, 0, 0, .22);
    outline: none;
}

.engagement-pin-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    margin-right: 8px;
}

@media (max-width: 1080px) {
    .engagement-dashboard-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .engagement-panel,
    .engagement-since-last,
    .engagement-imgd-panel,
    .engagement-timeline-panel,
    .engagement-figures-panel,
    .engagement-actions-panel,
    .engagement-risks-panel,
    .engagement-next-panel,
    .engagement-notes-panel {
        grid-column: span 3;
    }
}

@media (max-width: 760px) {
    body.engagement-copilot-mode-active #mode-engagement-copilot {
        padding: 16px 12px 24px;
    }

    .engagement-head,
    .engagement-summary-band {
        flex-direction: column;
        align-items: stretch;
    }

    .engagement-band-metrics,
    .engagement-dashboard-grid {
        grid-template-columns: 1fr;
    }

    .engagement-panel,
    .engagement-since-last,
    .engagement-imgd-panel,
    .engagement-timeline-panel,
    .engagement-figures-panel,
    .engagement-actions-panel,
    .engagement-risks-panel,
    .engagement-next-panel,
    .engagement-notes-panel {
        grid-column: 1;
    }

    .engagement-scope-grid {
        grid-template-columns: 1fr;
    }

    .engagement-timeline-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    #mode-tabs {
        width: 100%;
        overflow-x: auto;
        scrollbar-width: none;
        border-radius: 14px;
    }

    #mode-tabs::-webkit-scrollbar {
        display: none;
    }

    #mode-tabs-overlay {
        display: none;
    }

    .mode-tab-btn,
    .mode-tab-hl {
        flex: 0 0 auto;
        min-width: max-content;
        padding: 0 11px;
    }

    .mode-tab-btn[aria-selected="true"] {
        color: #fff;
        background: rgba(45, 127, 240, .88);
        box-shadow: 0 0 0 1px rgba(255, 255, 255, .18) inset;
    }
}

#mode-statistics {
    display: none;
}

body.statistics-mode-active #mode-statistics {
    display: flex;
    flex: 1;
    overflow-y: auto;
    padding: 28px 36px;
    flex-direction: column;
    gap: 18px;
}

body.statistics-mode-active #messages,
body.statistics-mode-active #input-area {
    display: none;
}

.statistics-hero {
    border: 1px solid var(--line);
    background:
        linear-gradient(135deg, rgba(50, 179, 107, .09), transparent 38%),
        linear-gradient(180deg, rgba(255, 255, 255, .045), rgba(255, 255, 255, .02));
    border-radius: 8px;
    padding: 20px;
}

.statistics-kicker,
.statistics-card-label {
    font-size: 9.5px;
    font-weight: 850;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: #7dd3a6;
}

.statistics-title {
    margin: 5px 0 6px;
    font-size: 23px;
    line-height: 1.12;
    font-weight: 900;
    color: var(--ink);
}

.statistics-sub {
    max-width: 680px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
    margin-bottom: 16px;
}

.statistics-search-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: stretch;
}

.statistics-search-bar textarea {
    min-height: 54px;
    resize: vertical;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    padding: 12px 14px;
    font: inherit;
    line-height: 1.45;
    outline: none;
}

.statistics-search-bar textarea:focus {
    border-color: rgba(125, 211, 166, .7);
    box-shadow: 0 0 0 3px rgba(50, 179, 107, .12);
}

.statistics-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.statistics-chip {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .035);
    color: var(--text);
    padding: 7px 10px;
    font: inherit;
    font-size: 11.5px;
    cursor: pointer;
}

.statistics-chip:hover {
    border-color: rgba(125, 211, 166, .5);
    background: rgba(50, 179, 107, .08);
}

.statistics-status {
    min-height: 18px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 11.5px;
}

.statistics-card {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr);
    gap: 14px;
    align-items: start;
}

.statistics-card-main,
.statistics-run-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    padding: 16px;
}

.statistics-card-main h3 {
    color: var(--ink);
    font-size: 18px;
    line-height: 1.25;
    margin: 6px 0 10px;
}

.statistics-answer {
    color: var(--text);
    font-size: 13px;
    line-height: 1.65;
}

.statistics-key-figures {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
}

.statistics-figure {
    min-width: 0;
    border: 1px solid rgba(125, 211, 166, .18);
    border-radius: 8px;
    background: rgba(50, 179, 107, .07);
    padding: 10px;
}

.statistics-figure-label,
.statistics-figure span:last-child {
    display: block;
    color: var(--muted);
    font-size: 10.5px;
    line-height: 1.35;
}

.statistics-figure strong {
    display: block;
    color: var(--ink);
    font-size: 20px;
    line-height: 1.15;
    margin: 3px 0;
    font-variant-numeric: tabular-nums;
}

.statistics-run-panel {
    background: #0d141b;
}

.statistics-data-runs,
.statistics-sources {
    display: grid;
    gap: 8px;
    margin-top: 9px;
}

.statistics-run {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 9px;
    padding: 9px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .045);
    border: 1px solid rgba(255, 255, 255, .06);
}

.statistics-run > span {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(125, 211, 166, .14);
    color: #b7f4ce;
    font-size: 10px;
    font-weight: 800;
}

.statistics-run strong,
.statistics-source strong,
.statistics-drive-row strong {
    display: block;
    color: var(--ink);
    font-size: 12px;
    line-height: 1.35;
}

.statistics-run em,
.statistics-source span,
.statistics-drive-row span {
    display: block;
    color: var(--faint);
    font-size: 10.5px;
    font-style: normal;
    line-height: 1.45;
}

.statistics-source-label {
    display: block;
    margin-top: 16px;
}

.statistics-source {
    padding: 9px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .035);
    border: 1px solid rgba(255, 255, 255, .055);
}

.statistics-source a {
    display: inline-block;
    margin-top: 5px;
    color: #93c5fd;
    font-size: 11px;
    text-decoration: none;
}

.statistics-drive-context,
.statistics-warnings {
    margin-top: 12px;
    display: grid;
    gap: 8px;
}

.statistics-drive-row,
.statistics-warnings > div,
.statistics-empty {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px;
    background: rgba(255, 255, 255, .035);
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.5;
}

.statistics-drive-row p {
    margin-top: 5px;
    color: var(--text);
    font-size: 11.5px;
    line-height: 1.5;
}

.statistics-warnings > div {
    border-color: rgba(228, 160, 43, .35);
    background: rgba(228, 160, 43, .08);
    color: #f3d18a;
}

@media (max-width: 800px) {
    body.statistics-mode-active #mode-statistics {
        padding: 18px;
    }
    .statistics-search-bar,
    .statistics-card,
    .statistics-key-figures {
        grid-template-columns: 1fr;
    }
}

/* ── Status / Klientbriefing ──────────────────────────────── */
#mode-status {
    display: none;
}

body.status-mode-active #mode-status {
    display: flex;
    flex: 1;
    overflow-y: auto;
    padding: 28px 36px;
    flex-direction: column;
    gap: 18px;
}

body.status-mode-active #messages,
body.status-mode-active #input-area {
    display: none;
}

.status-hero {
    border: 1px solid var(--line);
    background:
        linear-gradient(135deg, rgba(14, 165, 233, .07), transparent 38%),
        linear-gradient(180deg, rgba(255, 255, 255, .04), rgba(255, 255, 255, .015));
    border-radius: 8px;
    padding: 20px;
}

.status-kicker {
    font-size: 9.5px;
    font-weight: 850;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--status-blue);
}

.status-title {
    margin: 5px 0 6px;
    font-size: 23px;
    line-height: 1.12;
    font-weight: 900;
    color: var(--ink);
}

.status-sub {
    max-width: 680px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
    margin-bottom: 8px;
}

.status-mode-toggle {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.status-mode-btn {
    padding: 7px 16px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.status-mode-btn.active,
.status-mode-btn:hover {
    background: var(--status-blue);
    color: var(--ink);
    border-color: var(--status-blue);
}

.status-input-panel {
    margin-top: 12px;
}

.status-input-panel.hidden {
    display: none;
}

.status-doc-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 8px;
}

.status-doc-filter {
    display: grid;
    gap: 5px;
    min-width: 0;
}

.status-doc-filter span {
    color: var(--muted);
    font-size: 10px;
    font-weight: 850;
    letter-spacing: .09em;
    text-transform: uppercase;
}

.status-doc-filter input {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(8, 11, 15, .42);
    color: var(--text);
    padding: 9px 11px;
    outline: none;
}

.status-doc-filter input:focus {
    border-color: rgba(14, 165, 233, .68);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, .12);
}

.status-doc-count {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 11px;
    border: 1px solid rgba(14, 165, 233, .24);
    border-radius: 8px;
    background: rgba(14, 165, 233, .075);
    color: #bfe9ff;
    font-size: 11px;
    font-weight: 850;
    white-space: nowrap;
}

.status-doc-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 0 0 10px;
}

.status-doc-action-btn {
    min-height: 30px;
    border: 1px solid rgba(255, 255, 255, .09);
    border-radius: 8px;
    background: rgba(255, 255, 255, .035);
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    font-weight: 850;
    padding: 0 10px;
}

.status-doc-action-btn:hover {
    border-color: rgba(14, 165, 233, .42);
    background: rgba(14, 165, 233, .10);
    color: var(--ink);
}

.status-folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 8px;
}

.status-folder-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-2);
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
    user-select: none;
}

.status-folder-card:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, .35);
    border-color: var(--status-blue);
}

.status-folder-card .folder-icon {
    font-size: 20px;
}

.status-folder-card .folder-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    word-break: break-word;
}

.status-folder-card .folder-count {
    font-size: 11px;
    color: var(--muted);
}

.status-folder-card.empty {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

.status-doc-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: min(560px, 52vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 8px;
    background: rgba(8, 11, 15, .24);
}

.status-doc-group {
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
    overflow: hidden;
}

.status-doc-group-head {
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, .065);
    background: rgba(8, 11, 15, .32);
}

.status-doc-group-head strong {
    min-width: 0;
    color: var(--ink);
    font-size: 12px;
    font-weight: 850;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-doc-group-head span {
    color: var(--faint);
    font-size: 10.5px;
    font-weight: 850;
    white-space: nowrap;
}

.status-doc-group-items {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.status-doc-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 56px;
    padding: 10px 12px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    transition: background 0.12s, border-color 0.12s;
}

.status-doc-item:hover,
.status-doc-item.selected {
    background: rgba(14, 165, 233, .08);
    border-color: rgba(14, 165, 233, .16);
}

.status-doc-checkbox,
.status-doc-item input[type="checkbox"] {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: var(--status-blue);
    cursor: pointer;
}

.status-doc-main {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.status-doc-name {
    min-width: 0;
    color: var(--ink);
    font-size: 12.5px;
    line-height: 1.35;
    font-weight: 750;
    white-space: normal;
    overflow-wrap: anywhere;
}

.status-doc-meta {
    color: var(--faint);
    font-size: 10.5px;
    line-height: 1.35;
    font-weight: 750;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
}

.status-generate-btn {
    margin-top: 14px;
}

.status-generate-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.status-status-msg {
    font-size: 13px;
    color: var(--muted);
    padding: 8px 0;
}

.status-processing-card,
.status-error-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 14px;
    align-items: center;
    margin-top: 14px;
    padding: 14px;
    border: 1px solid rgba(14, 165, 233, .24);
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(14, 165, 233, .11), rgba(229, 70, 70, .045)),
        rgba(8, 11, 15, .42);
}

.status-processing-signal {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    position: relative;
}

.status-processing-signal span {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--status-blue);
    box-shadow: 0 0 20px rgba(14, 165, 233, .42);
    animation: statusPulse 1.55s ease-in-out infinite;
}

.status-processing-signal span:nth-child(2) {
    width: 28px;
    height: 28px;
    opacity: .28;
    animation-delay: .18s;
}

.status-processing-signal span:nth-child(3) {
    width: 44px;
    height: 44px;
    opacity: .13;
    animation-delay: .34s;
}

.status-processing-copy {
    min-width: 0;
}

.status-processing-eyebrow {
    color: var(--status-blue);
    font-size: 9.5px;
    font-weight: 900;
    letter-spacing: .11em;
    text-transform: uppercase;
}

.status-processing-title {
    margin-top: 3px;
    color: var(--ink);
    font-size: 16px;
    font-weight: 900;
    line-height: 1.25;
}

.status-processing-sub {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.status-processing-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.status-processing-steps span {
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 999px;
    background: rgba(255, 255, 255, .035);
    color: #bfe9ff;
    font-size: 10px;
    font-weight: 850;
    padding: 0 8px;
    animation: statusStepGlow 2.4s ease-in-out infinite;
}

.status-processing-steps span:nth-child(2) { animation-delay: .3s; }
.status-processing-steps span:nth-child(3) { animation-delay: .6s; }
.status-processing-steps span:nth-child(4) { animation-delay: .9s; }

.status-error-card {
    grid-template-columns: minmax(0, 1fr);
    border-color: rgba(241, 91, 80, .34);
    background: rgba(241, 91, 80, .075);
}

.status-error-card strong {
    color: #ffd0ce;
    font-size: 13px;
}

.status-error-card span {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

@keyframes statusPulse {
    0%, 100% { transform: scale(.78); opacity: .45; }
    50% { transform: scale(1); opacity: 1; }
}

@keyframes statusStepGlow {
    0%, 100% { border-color: rgba(255, 255, 255, .08); color: #9eb4bf; }
    42% { border-color: rgba(14, 165, 233, .42); color: #d9f4ff; }
}

.status-loading {
    font-size: 13px;
    color: var(--muted);
    padding: 12px 0;
}

.status-results {
    padding: 24px 0 0;
}

.status-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.status-results-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--muted);
}

.status-results-back {
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    background: none;
    border: none;
    font: inherit;
    padding: 4px 10px;
    border-radius: 6px;
    transition: background 0.12s;
}

.status-results-back:hover {
    background: rgba(255, 255, 255, .06);
}

.status-results-body {
    font-size: 15px;
    line-height: 1.75;
    color: var(--text);
}

.status-results-body h2 {
    font-size: 17px;
    font-weight: 700;
    margin: 28px 0 8px;
    color: var(--ink);
}

.status-results-body h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 20px 0 6px;
    color: var(--ink);
}

.status-results-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

.status-results-body th,
.status-results-body td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
}

.status-results-body th {
    font-weight: 600;
    color: var(--muted);
}

@media (max-width: 800px) {
    body.status-mode-active #mode-status {
        padding: 18px;
    }
    .status-hero {
        padding: 18px;
    }
    .status-folder-grid {
        grid-template-columns: 1fr 1fr;
    }
    .status-doc-toolbar {
        grid-template-columns: 1fr;
        align-items: stretch;
    }
    .status-doc-count {
        justify-content: flex-start;
    }
    .status-processing-card {
        grid-template-columns: 1fr;
    }
}

#mode-extern-analys {
    display: none;
}

body.extern-analys-mode-active #mode-extern-analys {
    display: flex;
    flex: 1;
    overflow-y: auto;
    padding: 28px 36px;
    flex-direction: column;
    gap: 0;
}

body.extern-analys-mode-active #messages,
body.extern-analys-mode-active #input-area {
    display: none;
}

/* Hero – heading + search */
.ea-hero {
    padding-bottom: 24px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--line);
}

.ea-hero-label {
    font-size: 22px;
    font-weight: 900;
    letter-spacing: -0.02em;
    color: var(--ink);
    line-height: 1.15;
    margin-bottom: 5px;
}

.ea-hero-sub {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.55;
    margin-bottom: 18px;
    max-width: 580px;
}

/* Search bar */
.related-search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
}
.related-search-bar input[type="text"] {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
    background: var(--surface-2);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}
.related-search-bar input[type="text"]::placeholder {
    color: var(--faint);
}
.related-search-bar input[type="text"]:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(45, 127, 240, 0.12);
}

/* Status */
.related-status {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 7px;
}

/* Results columns */
.related-results-wrapper {
    display: flex;
    gap: 36px;
    align-items: flex-start;
}
.related-section {
    flex: 1;
    min-width: 0;
}
.related-section-title {
    font-size: 9.5px;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--blue);
    margin: 0 0 14px;
    padding-bottom: 7px;
    border-bottom: 2px solid rgba(45, 127, 240, .2);
}
.related-subsection {
    margin-bottom: 22px;
}
.related-subsection-title {
    font-size: 9.5px;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--faint);
    margin: 0 0 7px;
}
.related-external-note {
    font-size: 11px;
    color: var(--muted);
    margin: -4px 0 10px;
    font-style: italic;
}

/* Cards */
.related-card {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 8px;
    transition: border-color .15s, background .15s;
    cursor: default;
}
.related-card:hover {
    border-color: rgba(45, 127, 240, .45);
    background: rgba(45, 127, 240, .04);
}
.related-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 3px;
}
.related-filename {
    font-weight: 700;
    font-size: 12px;
    color: var(--ink);
    word-break: break-all;
    line-height: 1.3;
}
.related-title {
    font-weight: 700;
    font-size: 12px;
    color: var(--blue);
    text-decoration: none;
    line-height: 1.3;
}
.related-title:hover {
    text-decoration: underline;
}
.related-score {
    font-size: 9.5px;
    color: var(--faint);
    white-space: nowrap;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
}
.related-card-meta {
    font-size: 10.5px;
    color: var(--faint);
    margin: 0 0 4px;
    line-height: 1.4;
}
.related-card-text {
    font-size: 11.5px;
    color: var(--text);
    line-height: 1.6;
}
.related-empty {
    font-size: 12px;
    color: var(--faint);
    padding: 10px 0;
    font-style: italic;
}

/* Badges */
.badge {
    font-size: 8.5px;
    font-weight: 850;
    padding: 2px 6px;
    border-radius: 5px;
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.badge-konsult   { background: #1e3a5f; color: #93c5fd; }
.badge-akademisk { background: #064e3b; color: #6ee7b7; }
.badge-white     { background: #451a03; color: #fde68a; }
.badge-case      { background: #2e1065; color: #c4b5fd; }
.badge-default   { background: var(--surface-3); color: var(--muted); }

.related-search-warning {
    color: #c0392b;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}
.related-search-empty {
    color: #7f8c8d;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

@media (max-width: 700px) {
    .related-results-wrapper { flex-direction: column; }
    #mode-extern-analys { padding: 18px; }
    .ea-hero { padding-bottom: 18px; margin-bottom: 18px; }
}

/* ============================================================
   CONTENT LAB
   ============================================================ */

:root {
    --cl-linkedin: #0a66c2;
    --cl-nyhetsbrev: #e4a02b;
    --cl-fallstudie: #32b36b;
    --cl-vitbok: #2d7ff0;
    --cl-forskning: #8b5cf6;
    --cl-forskning-soft: rgba(139, 92, 246, .12);
}

body.contentlab-mode-active #chat {
    background: linear-gradient(180deg, rgba(45, 127, 240, .04), transparent 200px),
                var(--bg);
}

body.contentlab-mode-active #messages,
body.contentlab-mode-active #input-area {
    display: none;
}

#mode-contentlab {
    display: none;
}

body.contentlab-mode-active #mode-contentlab {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Shell layout */
.contentlab-shell {
    display: flex;
    height: 100%;
    overflow: hidden;
}

/* Format sidebar */
.contentlab-format-sidebar {
    width: 200px;
    min-width: 200px;
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    padding: 16px 0;
    overflow-y: auto;
    gap: 2px;
}

.contentlab-sidebar-head {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0 16px 12px;
}

.contentlab-format-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 16px;
    background: none;
    border: none;
    border-left: 3px solid transparent;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: background .12s, border-color .12s;
    color: var(--text);
}

.contentlab-format-card:hover {
    background: rgba(255,255,255,.03);
}

.contentlab-format-card.active {
    background: rgba(255,255,255,.05);
}

.contentlab-format-card.active[data-cl-format="linkedin"] { border-left-color: var(--cl-linkedin); }
.contentlab-format-card.active[data-cl-format="nyhetsbrev"] { border-left-color: var(--cl-nyhetsbrev); }
.contentlab-format-card.active[data-cl-format="fallstudie"] { border-left-color: var(--cl-fallstudie); }
.contentlab-format-card.active[data-cl-format="vitbok"] { border-left-color: var(--cl-vitbok); }
.contentlab-format-card.active[data-cl-format="forskningssammanfattning"] { border-left-color: var(--cl-forskning); }

.cl-format-icon {
    font-size: 16px;
    line-height: 1.2;
    margin-top: 1px;
}

.cl-format-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cl-format-label {
    font-size: 13px;
    font-weight: 500;
}

.cl-format-desc {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.3;
}

/* Main panel */
.contentlab-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 16px;
    overflow-y: auto;
}

.contentlab-input-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.contentlab-input-area textarea {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    color: var(--text);
    font-size: 14px;
    resize: vertical;
    font-family: inherit;
    box-sizing: border-box;
}

.contentlab-input-area textarea:focus {
    outline: none;
    border-color: var(--cl-vitbok);
}

.contentlab-input-actions {
    display: flex;
    gap: 8px;
}

.contentlab-refine-area {
    display: flex;
    gap: 8px;
    align-items: center;
}

.contentlab-refine-area input {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
}

.contentlab-refine-area input:focus {
    outline: none;
    border-color: var(--cl-vitbok);
}

/* ── Shared Drive loader card (Content Lab + Extern Analys) ──────────────── */
.drive-loader-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 14px;
    align-items: center;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 8px;
    background: rgba(255, 255, 255, .03);
}

.drive-loader-signal {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    position: relative;
    flex-shrink: 0;
}

.drive-loader-signal span {
    position: absolute;
    border-radius: 50%;
    background: var(--loader-signal-color, var(--status-blue));
    animation: driveLoaderPulse 1.55s ease-in-out infinite;
}

.drive-loader-signal span:nth-child(1) {
    width: 14px;
    height: 14px;
    box-shadow: 0 0 20px var(--loader-signal-color, var(--status-blue));
}

.drive-loader-signal span:nth-child(2) {
    width: 28px;
    height: 28px;
    opacity: .28;
    animation-delay: .18s;
}

.drive-loader-signal span:nth-child(3) {
    width: 44px;
    height: 44px;
    opacity: .13;
    animation-delay: .34s;
}

.drive-loader-copy { min-width: 0; }

.drive-loader-eyebrow {
    color: var(--loader-signal-color, var(--status-blue));
    font-size: 9.5px;
    font-weight: 900;
    letter-spacing: .11em;
    text-transform: uppercase;
}

.drive-loader-title {
    margin-top: 3px;
    color: var(--ink);
    font-size: 15px;
    font-weight: 900;
    line-height: 1.25;
}

.drive-loader-sub {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.drive-loader-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.drive-loader-steps span {
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 999px;
    background: rgba(255, 255, 255, .035);
    color: rgba(255, 255, 255, .55);
    font-size: 10px;
    font-weight: 850;
    padding: 0 8px;
    animation: driveLoaderStepGlow 2.4s ease-in-out infinite;
}

.drive-loader-steps span:nth-child(2) { animation-delay: .3s; }
.drive-loader-steps span:nth-child(3) { animation-delay: .6s; }
.drive-loader-steps span:nth-child(4) { animation-delay: .9s; }
.drive-loader-steps span:nth-child(5) { animation-delay: 1.2s; }

@keyframes driveLoaderPulse {
    0%, 100% { transform: scale(.78); opacity: .45; }
    50% { transform: scale(1); opacity: 1; }
}

@keyframes driveLoaderStepGlow {
    0%, 100% { border-color: rgba(255, 255, 255, .08); color: rgba(255, 255, 255, .45); }
    42% { border-color: var(--loader-signal-color, var(--status-blue)); color: #fff; }
}

.contentlab-status {
    font-size: 13px;
    color: var(--text-muted);
}

/* Preview card */
.contentlab-preview {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.contentlab-preview::before {
    content: '';
    display: block;
    height: 3px;
    background: var(--cl-vitbok);
}

.contentlab-preview[data-format="linkedin"]::before { background: var(--cl-linkedin); }
.contentlab-preview[data-format="nyhetsbrev"]::before { background: var(--cl-nyhetsbrev); }
.contentlab-preview[data-format="fallstudie"]::before { background: var(--cl-fallstudie); }
.contentlab-preview[data-format="vitbok"]::before { background: var(--cl-vitbok); }
.contentlab-preview[data-format="forskningssammanfattning"]::before { background: var(--cl-forskning); }

.contentlab-preview-inner {
    padding: 20px;
}

.contentlab-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.contentlab-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}

.contentlab-preview-title {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.contentlab-preview-body {
    font-size: 14px;
    line-height: 1.65;
    white-space: normal;
    color: var(--text);
}

.contentlab-preview-body h2 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin: 16px 0 6px;
}

.contentlab-preview-body h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin: 14px 0 4px;
}

.contentlab-preview-body ul,
.contentlab-preview-body ol {
    margin: 6px 0 8px 18px;
    padding: 0;
}

.contentlab-preview-body li {
    margin-bottom: 3px;
}

.contentlab-newsletter-subject {
    font-size: 13px;
    font-weight: 600;
    color: var(--cl-nyhetsbrev, #4fa3e0);
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    letter-spacing: .2px;
}

.contentlab-sources {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    font-size: 12px;
    color: var(--text-muted);
}

.contentlab-sources summary {
    cursor: pointer;
    user-select: none;
    padding: 2px 0;
    list-style: none;
}

.contentlab-sources summary::-webkit-details-marker { display: none; }

.contentlab-sources summary::before {
    content: '▸ ';
    font-size: 10px;
}

details[open].contentlab-sources summary::before {
    content: '▾ ';
}

.contentlab-sources ul {
    margin: 6px 0 0 12px;
    padding: 0;
    list-style: none;
}

.contentlab-sources li {
    padding: 2px 0;
    color: var(--text-muted);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.linkedin-post-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.linkedin-char-count {
    font-size: 11px;
    font-weight: 600;
}

.linkedin-char-ok {
    color: var(--text-muted);
}

.linkedin-char-warn {
    color: #e07050;
}

.contentlab-preview-meta {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.contentlab-meta-item {
    font-size: 11px;
    color: var(--text-muted);
}

.contentlab-copy-btn {
    padding: 5px 12px;
    border-radius: 5px;
    font-size: 12px;
    border: 1px solid var(--line);
    background: none;
    color: var(--text);
    cursor: pointer;
    transition: background .12s;
}

.contentlab-copy-btn:hover {
    background: rgba(255,255,255,.05);
}

.contentlab-download-btn {
    padding: 5px 12px;
    border-radius: 5px;
    font-size: 12px;
    border: 1px solid var(--line);
    background: none;
    color: var(--text);
    cursor: pointer;
    transition: background .12s;
}

.contentlab-download-btn:hover {
    background: rgba(255,255,255,.05);
}

/* Mobile: sidebar becomes horizontal scroll */
@media (max-width: 640px) {
    .contentlab-shell {
        flex-direction: column;
    }

    .contentlab-format-sidebar {
        width: 100%;
        min-width: unset;
        border-right: none;
        border-bottom: 1px solid var(--line);
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 8px;
        gap: 4px;
    }

    .contentlab-sidebar-head {
        display: none;
    }

    .contentlab-format-card {
        flex-direction: column;
        align-items: center;
        padding: 8px 12px;
        min-width: 80px;
        border-left: none;
        border-bottom: 3px solid transparent;
        white-space: nowrap;
    }

    .contentlab-format-card.active[data-cl-format="linkedin"] { border-bottom-color: var(--cl-linkedin); border-left-color: transparent; }
    .contentlab-format-card.active[data-cl-format="nyhetsbrev"] { border-bottom-color: var(--cl-nyhetsbrev); border-left-color: transparent; }
    .contentlab-format-card.active[data-cl-format="fallstudie"] { border-bottom-color: var(--cl-fallstudie); border-left-color: transparent; }
    .contentlab-format-card.active[data-cl-format="vitbok"] { border-bottom-color: var(--cl-vitbok); border-left-color: transparent; }
    .contentlab-format-card.active[data-cl-format="forskningssammanfattning"] { border-bottom-color: var(--cl-forskning); border-left-color: transparent; }

    .cl-format-desc {
        display: none;
    }

    .contentlab-main {
        padding: 16px;
    }
}
