/* ── Theme variables ─────────────────────────────────────────────────────── */
:root {
    --bg-page:         #f0f2f5;
    --bg-surface:      #ffffff;
    --bg-surface-2:    #f8fafc;
    --text-primary:    #1a1a2e;
    --text-secondary:  #6b7280;
    --text-muted:      #9ca3af;
    --border:          #e5e7eb;
    --border-input:    #d1d5db;
    --accent:          #2563eb;
    --accent-hover:    #1d4ed8;
    --accent-disabled: #93c5fd;
    --bubble-user-bg:  #2563eb;
    --bubble-user-fg:  #ffffff;
    --bubble-bot-bg:   #ffffff;
    --bubble-bot-fg:   #1a1a2e;
    --code-bg:         #f1f5f9;
    --pre-bg:          #1e293b;
    --pre-fg:          #e2e8f0;
    --shadow-sm:       0 1px 3px rgba(0,0,0,.06);
    --shadow-md:       0 4px 24px rgba(0,0,0,.08);
    --shadow-card:     0 1px 3px rgba(0,0,0,.08);
}

[data-theme="dark"] {
    --bg-page:         #0f172a;
    --bg-surface:      #1e293b;
    --bg-surface-2:    #162032;
    --text-primary:    #e2e8f0;
    --text-secondary:  #94a3b8;
    --text-muted:      #64748b;
    --border:          #334155;
    --border-input:    #475569;
    --accent:          #3b82f6;
    --accent-hover:    #2563eb;
    --accent-disabled: #1e3a5f;
    --bubble-user-bg:  #2563eb;
    --bubble-user-fg:  #ffffff;
    --bubble-bot-bg:   #1e293b;
    --bubble-bot-fg:   #e2e8f0;
    --code-bg:         #0f172a;
    --pre-bg:          #0f172a;
    --pre-fg:          #e2e8f0;
    --shadow-sm:       0 1px 3px rgba(0,0,0,.3);
    --shadow-md:       0 4px 24px rgba(0,0,0,.4);
    --shadow-card:     0 1px 3px rgba(0,0,0,.3);
}

/* ── Reset / Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    transition: background .2s, color .2s;
}

#app { height: 100%; }

/* ── App Shell ───────────────────────────────────────────────────────────── */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    height: 52px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 100;
}

.header-brand { display: flex; align-items: center; }
.header-logo  { height: 32px; width: auto; }

/* header-pinned: always visible in header */
.header-pinned { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }

/* ── App body: sidebar + main (below header) ─────────────────────────────── */
.app-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ── Desktop sidebar ─────────────────────────────────────────────────────── */
.app-sidebar {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
}

/* New chat button */
.sidebar-new-chat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 0.75rem 0.25rem;
    padding: 0.5rem 0.875rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: none;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s;
    flex-shrink: 0;
}
.sidebar-new-chat:hover { background: var(--bg-surface-2); }
.sidebar-new-chat svg   { flex-shrink: 0; }

/* ── Sidebar index drop-zone ──────────────────────────────────────────────
   Rectangular section at the top of the sidebar, sized to the bar width.
   Click → file picker. Drag-drop a file → uploads to /api/chat/index for
   async server-side extraction by Argo (DocumentIndexJob). Theme-aware:
   tracks light/dark via the same CSS variables as the rest of the sidebar. */
.sidebar-dropzone {
    margin: 0.4rem 0.75rem 0.6rem;
    padding: 0.9rem 0.75rem 0.85rem;
    border: 1.5px dashed var(--border);
    border-radius: 8px;
    background: var(--bg-surface-2);
    color: var(--text-secondary);
    cursor: pointer;
    text-align: center;
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    transition: border-color .18s ease, background .18s ease, color .18s ease;
    flex-shrink: 0;
}
.sidebar-dropzone:hover,
.sidebar-dropzone.drag-over {
    border-color: var(--accent);
    background: var(--bg-surface);
    color: var(--text-primary);
}
.sidebar-dropzone.drag-over {
    border-style: solid;
}
.sidebar-dropzone.uploading {
    cursor: progress;
    opacity: 0.85;
}
.sidebar-dropzone.success {
    border-color: #16a34a;
    color: #16a34a;
    border-style: solid;
}
.sidebar-dropzone.error {
    border-color: #dc2626;
    color: #dc2626;
    border-style: solid;
}
.sidebar-dropzone-icon {
    opacity: 0.65;
    margin-bottom: 0.1rem;
}
.sidebar-dropzone:hover .sidebar-dropzone-icon,
.sidebar-dropzone.drag-over .sidebar-dropzone-icon,
.sidebar-dropzone.success .sidebar-dropzone-icon,
.sidebar-dropzone.error .sidebar-dropzone-icon {
    opacity: 1;
}
.sidebar-dropzone-label {
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.25;
}
.sidebar-dropzone-hint {
    font-size: 0.66rem;
    opacity: 0.75;
    line-height: 1.2;
}

/* Session list */
.sidebar-sessions {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 0.25rem 0;
    min-height: 0;
}

.sidebar-section-label {
    padding: 0.375rem 0.875rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    flex-shrink: 0;
}
.sidebar-group-label {
    padding: 0.5rem 0.875rem 0.15rem;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-top: 0.25rem;
}
.sidebar-group-label:first-child { margin-top: 0; }

.sidebar-session {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 0.375rem 0 0.75rem;
    border-radius: 8px;
    margin: 0 0.375rem;
    transition: background .12s;
}
.sidebar-session:hover { background: var(--bg-surface-2); }
.sidebar-session.active { background: var(--bg-surface-2); }

.sidebar-session-link {
    flex: 1;
    padding: 0.4rem 0.25rem 0.4rem 0.125rem;
    font-size: 0.8125rem;
    color: var(--text-primary);
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
}
.sidebar-session.active .sidebar-session-link { color: var(--accent); font-weight: 500; }

.sidebar-session-actions {
    flex-shrink: 0;
    display: none;
    align-items: center;
}
.sidebar-session:hover .sidebar-session-actions { display: flex; }

.sidebar-session-btn {
    display: flex; align-items: center; justify-content: center;
    width: 26px; height: 26px;
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); border-radius: 5px;
    transition: background .12s, color .12s;
    padding: 0;
}
.sidebar-session-btn:hover { background: var(--bg-surface-3, var(--border)); color: var(--text-primary); }

/* Session rename input */
.sidebar-session-rename {
    flex: 1;
    padding: 0.25rem 0.375rem;
    font-size: 0.8125rem;
    background: var(--bg-input, var(--bg-surface-2));
    border: 1px solid var(--accent);
    border-radius: 5px;
    color: var(--text-primary);
    outline: none;
    min-width: 0;
}

/* Sidebar nav footer */
.sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding: 0.5rem 0;
}

.sidebar-user-footer {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
}
.sidebar-user-info  { flex: 1; display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.sidebar-user-name  { font-size: 0.8125rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-email { font-size: 0.7rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role  { font-size: 0.68rem; color: var(--accent); font-weight: 500; }

/* Bell button */
.bell-btn {
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); border-radius: 8px;
    transition: background .15s, color .15s;
    position: relative;
}
.bell-btn:hover:not(:disabled) { background: var(--bg-surface-2); color: var(--text-primary); }
.bell-btn:disabled { opacity: 0.45; cursor: default; }
.bell-btn.active { background: var(--bg-surface-2); color: var(--text-primary); }

/* Unread count badge */
.bell-badge {
    position: absolute;
    top: 4px; right: 4px;
    min-width: 16px; height: 16px;
    padding: 0 3px;
    background: #ef4444;
    color: #fff;
    font-size: 0.65rem; font-weight: 700; line-height: 16px;
    border-radius: 8px;
    text-align: center;
    pointer-events: none;
}

/* Notifications dropdown */
.notif-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 320px;
    max-height: 420px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
    z-index: 1000;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.notif-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 1rem;
    font-size: 0.8rem; font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.notif-mark-all {
    background: none; border: none; cursor: pointer;
    font-size: 0.72rem; color: var(--accent-primary);
    padding: 0;
}
.notif-mark-all:hover { text-decoration: underline; }
.notif-empty {
    padding: 2rem 1rem;
    text-align: center;
    font-size: 0.8rem; color: var(--text-muted);
}
.notif-list { overflow-y: auto; flex: 1; }
.notif-item {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background .12s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-surface-2); }
.notif-item.unread { background: color-mix(in srgb, var(--accent-primary) 6%, transparent); }
.notif-item.unread:hover { background: color-mix(in srgb, var(--accent-primary) 10%, transparent); }
.notif-item-title {
    font-size: 0.78rem; font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.notif-item-body {
    font-size: 0.74rem; color: var(--text-secondary);
    margin-top: 2px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}
.notif-item-time {
    font-size: 0.68rem; color: var(--text-muted);
    margin-top: 3px;
}

/* Hamburger: hidden on desktop */
.hamburger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 36px; height: 36px;
    background: none; border: none; cursor: pointer;
    padding: 6px; border-radius: 8px;
    color: var(--text-primary);
    transition: background .15s;
}
.hamburger-btn:hover { background: var(--bg-surface-2); }
.hamburger-btn span {
    display: block; width: 20px; height: 2px;
    background: currentColor; border-radius: 2px;
    transition: transform .2s, opacity .2s;
}

/* Sidebar backdrop: hidden on desktop */
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 299;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
}
.sidebar-backdrop.visible { opacity: 1; pointer-events: auto; }

/* Sidebar brand: hidden on desktop */
.sidebar-brand { display: none; }

/* usage-dropdown-hidden: hides the dropdown on desktop when closed.
   Use !important to beat .usage-dropdown { display: flex } which has equal specificity but comes later. */
.usage-dropdown-hidden { display: none !important; }

/* ── Mobile sidebar ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .header-brand { flex: 1; }
    .header-pinned { margin-left: 0; }

    /* Show hamburger on mobile */
    .hamburger-btn { display: flex; }

    /* Show backdrop on mobile (invisible/non-interactive until .visible) */
    .sidebar-backdrop { display: block; pointer-events: none; }

    /* Sidebar becomes a fixed overlay panel on mobile */
    .app-sidebar {
        position: fixed;
        top: 0; left: 0;
        width: min(280px, 85vw);
        height: 100dvh;
        border-right: 1px solid var(--border);
        box-shadow: var(--shadow-md);
        z-index: 300;
        transform: translateX(-110%);
        transition: transform .25s cubic-bezier(.4,0,.2,1);
    }
    .app-sidebar.open { transform: translateX(0); }

    /* Sidebar brand: only visible on mobile */
    .sidebar-brand {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.875rem 1rem;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
    }
    .sidebar-close-btn {
        display: flex; align-items: center; justify-content: center;
        width: 32px; height: 32px;
        background: none; border: none; cursor: pointer;
        color: var(--text-muted); border-radius: 6px;
        transition: background .15s;
    }
    .sidebar-close-btn:hover { background: var(--bg-surface-2); }
}

/* ── Sidebar navigation links (visible on desktop + mobile) ─────────────── */
.sidebar-divider { height: 1px; background: var(--border); margin: 4px 0; flex-shrink: 0; }

.sidebar-link {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.55rem 0.875rem;
    font-size: 0.875rem; color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    margin: 0 0.375rem;
    transition: background .1s, color .1s;
}
.sidebar-link:hover { background: var(--bg-surface-2); color: var(--text-primary); }

.sidebar-logout {
    display: flex; align-items: center; gap: 0.5rem;
    width: calc(100% - 0.75rem); margin: 0 0.375rem;
    padding: 0.55rem 0.5rem;
    font-size: 0.875rem; color: #ef4444;
    background: none; border: none; cursor: pointer;
    border-radius: 8px;
    transition: background .1s;
    text-align: left;
}
.sidebar-logout:hover { background: var(--bg-surface-2); }

.app-main {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── Header user menu ────────────────────────────────────────────────────── */
.header-user-menu { position: relative; }

.avatar-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    color: var(--text-primary);
    transition: background .15s;
}
.avatar-btn:hover { background: var(--bg-surface-2); }

.header-username {
    font-size: 0.875rem;
    font-weight: 500;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chevron-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform .15s;
}
.chevron-icon.open { transform: rotate(180deg); }

.user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    min-width: 180px;
    z-index: 120;
    overflow: hidden;
    padding: 4px 0;
}

.user-dropdown a,
.user-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.55rem 1rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background .1s;
}
.user-dropdown a:hover,
.user-dropdown button:hover { background: var(--bg-surface-2); }

.user-dropdown .btn-logout { color: #ef4444; }

/* ── Usage widget ────────────────────────────────────────────────────────── */

.usage-widget { position: relative; }

.usage-pill {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.usage-pill:hover { background: var(--bg-surface-2); }
.usage-pill .usage-icon { color: var(--text-muted); flex-shrink: 0; }

.usage-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    width: 220px;
    z-index: 120;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.usage-dropdown-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border);
}

.usage-row { display: flex; flex-direction: column; gap: 0.3rem; }

.usage-row-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-primary);
}
.usage-count { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.usage-label { font-size: 0.75rem; }

.usage-bar-bg {
    height: 6px;
    background: var(--bg-surface-2);
    border-radius: 999px;
    overflow: hidden;
}
.usage-bar-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
    transition: width .3s ease;
}
.usage-bar-fill.usage-bar-warn   { background: #f59e0b; }
.usage-bar-fill.usage-bar-danger { background: #ef4444; }

.usage-upgrade-btn {
    display: block;
    text-align: center;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    margin-top: 0.15rem;
    transition: opacity .15s;
}
.usage-upgrade-btn:hover { opacity: 0.88; }

/* ── Chat ────────────────────────────────────────────────────────────────── */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
}

/* ── Empty state: welcome centered ──────────────────────────────────────── */
.chat-container.chat-empty {
    justify-content: center;
    gap: 1.25rem;
    padding-bottom: 4rem;
}
.chat-container.chat-empty .chat-messages {
    display: none;
}
.chat-container.chat-empty .chat-input-bar {
    max-width: 700px;
    width: 100%;
    margin: 0 auto;
}

.chat-welcome {
    text-align: center;
    padding: 0 1rem;
    animation: fadeInUp 0.35s ease;
}
.chat-welcome-title {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 0.4rem;
    color: var(--text-primary);
}
.chat-welcome-sub {
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 0;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
}

/* Chat font variants */
.chat-messages.font-sans    { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.chat-messages.font-system  { font-family: system-ui, sans-serif; }
.chat-messages.font-dyslexic { font-family: 'OpenDyslexic', cursive; }

/* Chat size variants */
.chat-messages.size-medium .message-bubble { font-size: 1.05rem; }
.chat-messages.size-large  .message-bubble { font-size: 1.15rem; }

.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.message-user  { align-self: flex-end;  align-items: flex-end; }
.message-bot   { align-self: flex-start; align-items: flex-start; }

.message-bubble {
    padding: 0.6rem 0.9rem;
    border-radius: 18px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.95rem;
}

/* Markdown content inside bot bubbles */
.message-markdown { white-space: normal; }
.message-markdown p  { margin: 0 0 0.4rem; }
.message-markdown p:last-child { margin-bottom: 0; }
.message-markdown ul, .message-markdown ol { margin: 0.25rem 0 0.4rem 1.25rem; padding: 0; }
.message-markdown li { margin-bottom: 0.1rem; }
.message-markdown code { background: var(--code-bg); border-radius: 4px; padding: 0.1em 0.35em; font-size: 0.88em; }
.message-markdown pre { background: var(--pre-bg); color: var(--pre-fg); border-radius: 8px; padding: 0.75rem 1rem; overflow-x: auto; margin: 0.4rem 0; }
.message-markdown pre code { background: none; padding: 0; color: inherit; font-size: 0.85em; }
.message-markdown h1,.message-markdown h2,.message-markdown h3 { font-weight: 600; margin: 0.5rem 0 0.25rem; line-height: 1.3; }
.message-markdown h1 { font-size: 1.1rem; }
.message-markdown h2 { font-size: 1rem; }
.message-markdown h3 { font-size: 0.95rem; }
.message-markdown strong { font-weight: 600; }
.message-markdown blockquote { border-left: 3px solid var(--border); margin: 0.4rem 0; padding-left: 0.75rem; color: var(--text-secondary); }

.message-user .message-bubble {
    background: var(--bubble-user-bg);
    color: var(--bubble-user-fg);
    border-bottom-right-radius: 4px;
}

.message-bot .message-bubble {
    background: var(--bubble-bot-bg);
    color: var(--bubble-bot-fg);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-card);
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0 2px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Typing indicator ────────────────────────────────────────────────────── */
.typing-indicator { display: flex; gap: 5px; align-items: center; padding: 0.7rem 1rem; }
.typing-indicator span { width: 8px; height: 8px; background: var(--text-muted); border-radius: 50%; animation: bounce 1.2s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%            { transform: translateY(-8px); }
}

.processing-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.1rem 1rem 0.5rem;
    max-width: 360px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    animation: fade-status 0.3s ease-in;
}
@keyframes fade-status {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Model selector bar ──────────────────────────────────────────────────── */
.chat-model-bar {
    display: flex;
    gap: 0.4rem;
    padding: 0.4rem 1rem 0;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.model-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.78rem;
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
    white-space: nowrap;
}

.model-chip:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.model-chip.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.model-chip-mult {
    opacity: 0.75;
    font-size: 0.72rem;
}

.model-chip.active .model-chip-mult {
    opacity: 0.9;
}

/* ── Input bar ───────────────────────────────────────────────────────────── */
.chat-input-bar {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.6rem 1rem 0.5rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    flex: 1;
    min-width: 0;
}
.chat-input-bar.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}

/* ── Input row (textarea + send) ─────────────────────────────────────────── */
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

/* ── Toolbar row ─────────────────────────────────────────────────────────── */
.chat-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-toolbar-left  { display: flex; align-items: center; gap: 0.25rem; }
.chat-toolbar-right { display: flex; align-items: center; gap: 0.25rem; }

/* ── (+) button ──────────────────────────────────────────────────────────── */
.plus-menu-wrapper {
    position: relative;
}
.btn-plus {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px;
    border-radius: 50%;
    border: 1.5px solid var(--border-input);
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    transition: color .15s, border-color .15s, background .15s;
}
.btn-plus:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.btn-plus.active               { color: var(--accent); border-color: var(--accent); }
.btn-plus:disabled             { opacity: .45; cursor: default; }

.plus-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    min-width: 160px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,.12);
    padding: 0.3rem 0;
    z-index: 200;
}
.plus-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.45rem 0.85rem;
    background: none;
    border: none;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
}
.plus-menu-item:hover { background: var(--bg-hover); }

/* ── Index drop zone ─────────────────────────────────────────────────────── */
.chat-bottom-wrapper {
    display: flex;
    align-items: stretch;
    flex-shrink: 0;
}
/* Index drop-zone moved to the sidebar — see .sidebar-dropzone above. */
.chat-container.chat-empty .chat-input-bar { border-radius: 12px; border: 1px solid var(--border); }

/* ── Attach chips ────────────────────────────────────────────────────────── */
.attach-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
}
.attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.5rem 0.2rem 0.45rem;
    border-radius: 99px;
    background: var(--bg-muted);
    border: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-secondary);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.attach-chip svg { flex-shrink: 0; }
.attach-chip-remove {
    background: none;
    border: none;
    padding: 0;
    margin-left: 0.1rem;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    flex-shrink: 0;
}
.attach-chip-remove:hover { color: var(--text-primary); }

.chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border-input);
    border-radius: 12px;
    padding: 0.6rem 0.9rem;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    max-height: 160px;
    overflow-y: auto;
    line-height: 1.5;
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color .15s;
}
.chat-input:focus { border-color: var(--accent); }

.btn-send {
    width: 42px; height: 42px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s;
}
.btn-send:hover:not(:disabled)  { background: var(--accent-hover); }
.btn-send:disabled               { background: var(--accent-disabled); cursor: default; }

/* Stop-generating state — the send button turns into a dark square while the
   assistant is thinking; clicking it aborts the in-flight request. */
.btn-send.btn-stop               { background: #2c2c2c; }
.btn-send.btn-stop:hover         { background: #000; }
[data-bs-theme="dark"] .btn-send.btn-stop       { background: #e5e7eb; color: #111; }
[data-bs-theme="dark"] .btn-send.btn-stop:hover { background: #fff; }

.btn-mic {
    position: relative;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--border-input);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color .15s, border-color .15s, background .15s;
}
.btn-mic:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.btn-mic:disabled              { opacity: .45; cursor: default; }
.btn-mic.recording             { color: #ef4444; border-color: #ef4444; background: rgba(239,68,68,.08); }
.btn-mic.recording::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid #ef4444;
    animation: mic-pulse 1.2s ease-out infinite;
    pointer-events: none;
}
@keyframes mic-pulse {
    0%   { transform: scale(1);   opacity: .7; }
    100% { transform: scale(1.6); opacity: 0;  }
}
.spin { animation: kibo-spin .8s linear infinite; }
@keyframes kibo-spin { to { transform: rotate(360deg); } }

/* ── Thinking steps ──────────────────────────────────────────────────────── */
.thinking-steps   { font-size: 0.78rem; color: var(--text-secondary); max-width: 100%; }
.thinking-summary { cursor: pointer; color: var(--text-muted); font-style: italic; }
.thinking-step    { padding: 2px 0 2px 6px; border-left: 2px solid var(--border); margin-top: 2px; }

/* ── Action trace ────────────────────────────────────────────────────────── */
.action-trace         { font-size: 0.8rem; margin-bottom: 0.25rem; }
.action-trace-summary {
    cursor: pointer; color: var(--fg-muted, #888); font-size: 0.8rem;
    list-style: none; display: inline-flex; align-items: center; gap: 0.3rem;
    -webkit-user-select: none; user-select: none;
}
.action-trace-row {
    display: flex; flex-wrap: wrap; align-items: baseline;
    gap: 0.3rem; padding: 0.18rem 0.5rem;
    border-left: 2px solid var(--border); margin: 0.15rem 0;
    font-family: ui-monospace, monospace;
}
.action-trace-error   { border-left-color: #e55; }
.action-trace-plugin  { color: var(--accent); font-weight: 600; font-size: 0.75rem; }
.action-trace-name    { color: var(--fg); font-size: 0.75rem; }
.action-trace-params  { color: var(--fg-muted, #888); font-size: 0.72rem; flex: 1; }
.action-trace-result  { color: var(--fg-muted, #888); font-size: 0.72rem; font-style: italic; }
.action-trace-error .action-trace-result { color: #e55; }

/* ── Choices (radio / checkbox) ─────────────────────────────────────────── */
.choices-group    { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.choice-btn {
    background: var(--surface-alt, #f0f4ff);
    border: 1.5px solid var(--accent);
    border-radius: 999px;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.88rem;
    padding: 0.3rem 0.85rem;
    transition: background 0.15s, color 0.15s;
}
.choice-btn:hover { background: var(--accent); color: #fff; }
.choice-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.choice-btn-confirm { border-radius: 6px; font-weight: 600; }
.choice-check {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.88rem; cursor: pointer;
    background: var(--surface-alt, #f0f4ff);
    border: 1.5px solid var(--border);
    border-radius: 6px;
    padding: 0.3rem 0.7rem;
}
.choice-check:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ── Compose (email draft) ───────────────────────────────────────────────── */
.compose-group   { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; width: 100%; }
.compose-from    { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.compose-from select { font-size: 0.85rem; padding: 0.2rem 0.4rem; border-radius: 6px;
                        border: 1px solid var(--border-input); background: var(--bg-surface-2);
                        color: var(--text-primary); cursor: pointer; }
.compose-label   { color: var(--text-muted); white-space: nowrap; }
.compose-busy    { font-size: 0.8rem; color: var(--text-muted); font-style: italic; }
.compose-meta    { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--text-muted); padding: 0.4rem 0.6rem; background: var(--bg-surface-2); border-radius: 8px; }
.compose-subject { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.compose-subject-input { flex: 1; font-size: 0.88rem; font-family: inherit; padding: 0.4rem 0.6rem;
                   border: 1px solid var(--border-input); border-radius: 8px; outline: none;
                   background: var(--bg-surface-2); color: var(--text-primary); transition: border-color .15s; }
.compose-subject-input:focus { border-color: var(--accent); }
.compose-attachments { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: 0.85rem; }
.compose-attachment-chip { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.8rem;
                   padding: 0.2rem 0.55rem; border-radius: 999px; background: var(--bg-surface-2);
                   border: 1px solid var(--border-input); color: var(--text-primary); }
.compose-body    { width: 100%; resize: none; border: 1px solid var(--border-input); border-radius: 10px;
                   padding: 0.55rem 0.75rem; font-size: 0.88rem; font-family: inherit; line-height: 1.45;
                   outline: none; background: var(--bg-surface-2); color: var(--text-primary);
                   overflow-y: auto; scrollbar-width: none; field-sizing: content;
                   min-height: 4rem; max-height: 300px; transition: border-color .15s; display: block; }
.compose-body::-webkit-scrollbar { display: none; }
.compose-body:focus { border-color: var(--accent); }
.compose-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.compose-send    { border-radius: 8px !important; font-weight: 600; font-size: 0.85rem; }
.compose-status  { font-size: 0.8rem; color: var(--text-muted); font-style: italic; }
.choice-btn-secondary { background: var(--bg-surface-2) !important; color: var(--text-primary) !important;
                         border: 1px solid var(--border) !important; border-radius: 8px !important; font-size: 0.85rem; }
.choice-btn-danger    { background: transparent !important; color: var(--text-muted) !important;
                         border: 1px solid var(--border) !important; border-radius: 8px !important; font-size: 0.85rem; }
.choice-btn-danger:hover { color: var(--danger, #ef4444) !important; border-color: var(--danger, #ef4444) !important; }

/* ── Auth page ───────────────────────────────────────────────────────────── */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 2rem 1rem;
}

.auth-card {
    background: var(--bg-surface);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-md);
}

.auth-logo { text-align: center; margin-bottom: 1.75rem; }
.auth-logo-img { height: 56px; width: auto; }

.auth-divider {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin: 1.25rem 0;
    color: var(--text-muted);
    font-size: .8rem;
}
.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: .55rem 1rem;
    font-size: .9rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, border-color .15s;
}
.btn-google:hover {
    background: var(--bg-surface-2);
    border-color: var(--accent);
    color: var(--text-primary);
    text-decoration: none;
}

/* ── Settings page ───────────────────────────────────────────────────────── */
.settings-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
}

.settings-sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    overflow-y: auto;
}

.settings-sidebar-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    padding: 0.5rem 1.25rem 0.25rem;
    margin-top: 0.75rem;
}
.settings-sidebar-title:first-child { margin-top: 0; }

.settings-nav-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.55rem 1.25rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 0;
    transition: background .1s;
}
.settings-nav-btn:hover  { background: var(--bg-surface-2); }
.settings-nav-btn.active { background: var(--bg-surface-2); color: var(--accent); font-weight: 500; }

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

.settings-section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.settings-group {
    max-width: 520px;
    margin-bottom: 2rem;
}

.settings-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: var(--text-primary);
}

.settings-group .form-control {
    background: var(--bg-surface);
    border-color: var(--border-input);
    color: var(--text-primary);
}
.settings-group .form-control:focus { border-color: var(--accent); box-shadow: none; }

/* Canonical small descriptive text under a field/control. Use this everywhere
   instead of Bootstrap's .form-text or inline font-size/color styles. */
.field-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    margin-bottom: 0;
}

/* Canonical sub-section header inside a settings panel (e.g. "Gmail",
   "Calendar"). Replaces the repeated inline uppercase/letter-spacing style. */
.settings-subhead {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.settings-success { color: #16a34a; font-size: 0.875rem; margin-top: 0.5rem; }
.settings-error   { color: #dc2626; font-size: 0.875rem; margin-top: 0.5rem; }

.settings-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    cursor: pointer;
    font-weight: 500;
    /* This row also carries Bootstrap's .form-check, which reserves a left
       gutter (padding-left:1.5em) and floats the input left with a negative
       margin — both meant for a checkbox ON THE LEFT. Here the switch sits on
       the RIGHT via flex, so neutralize them to avoid the phantom left padding
       and the overlap. */
    padding-left: 0;
    min-height: 0;
    margin-bottom: 0;
}
.settings-toggle-row .form-check-input {
    float: none;
    margin-left: 0;
    margin-top: 0;
    flex-shrink: 0;
}

/* Theme/font option cards */
.option-cards {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.option-card {
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 0.6rem 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color .15s, background .15s;
    min-width: 90px;
    text-align: center;
}
.option-card:hover   { border-color: var(--accent); }
.option-card.active  { border-color: var(--accent); background: var(--bg-surface-2); color: var(--accent); font-weight: 500; }

/* Theme visual preview cards */
.preview-cards {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.preview-card {
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    background: transparent;
    padding: 0;
    overflow: hidden;
    text-align: center;
    transition: border-color .15s, box-shadow .15s;
    display: flex;
    flex-direction: column;
}
.preview-card:hover  { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.preview-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.preview-card svg { display: block; width: 100px; height: 70px; }

.preview-card-label {
    font-size: .78rem;
    padding: .3rem .5rem .4rem;
    color: var(--text-primary);
    display: block;
    background: var(--bg-surface);
}
.preview-card.active .preview-card-label { color: var(--accent); font-weight: 600; }

/* Font preview cards */
.font-preview-aa {
    display: block;
    font-size: 2rem;
    line-height: 1;
    padding: .55rem .75rem .25rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    min-width: 70px;
}
.font-preview-aa.font-sans     { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.font-preview-aa.font-system   { font-family: system-ui, sans-serif; }
.font-preview-aa.font-dyslexic { font-family: 'OpenDyslexic', cursive; } /* loaded via kiboLoadFont */

/* Org ID copy box */
.copy-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
}
.copy-box button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    font-size: 0.8rem;
    transition: color .15s;
}
.copy-box button:hover { color: var(--accent); }

/* Placeholder sections */
.placeholder-section {
    padding: 2rem;
    background: var(--bg-surface-2);
    border: 1px dashed var(--border);
    border-radius: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ── Setup page ──────────────────────────────────────────────────────────── */
.setup-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1rem;
    background: var(--bg-page);
}

.setup-card {
    background: var(--bg-surface);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-md);
}

.setup-card h2 { margin: 0 0 0.5rem; font-size: 1.3rem; }
.setup-card .subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.75rem; }

/* Wizard progress dots */
.wizard-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 1.75rem;
}
.wizard-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}
.wizard-dot.active  { background: var(--accent); transform: scale(1.25); }
.wizard-dot.done    { background: var(--accent); opacity: 0.45; }
.wizard-line {
    flex: 1;
    height: 2px;
    background: var(--border);
    max-width: 28px;
}

/* Wizard role/referral option pills */
.wizard-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.wizard-option-pill {
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    border: 1.5px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: border-color 0.15s, background 0.15s;
}
.wizard-option-pill:hover,
.wizard-option-pill.selected {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* Wizard nav buttons */
.wizard-nav {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}
.wizard-nav .btn { flex: 1; }

/* Welcome step icon */
.wizard-welcome-icon {
    font-size: 3rem;
    text-align: center;
    margin-bottom: 0.75rem;
}
.wizard-integration-prompt {
    background: var(--bg-page);
    border-radius: 10px;
    padding: 1rem;
    margin: 1rem 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
}

/* Wizard provider cards (connect step) */
.wizard-provider-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.wizard-provider-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    background: var(--bg-page);
    border-radius: 10px;
    border: 1px solid var(--border);
}
.wizard-provider-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    flex-shrink: 0;
}
.wizard-provider-name {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Wizard Welcome examples */
.wizard-welcome-examples {
    margin-top: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.wizard-welcome-try {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 0.25rem;
}
.wizard-welcome-msg {
    display: block;
    padding: 0.55rem 0.85rem;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--accent);
    text-decoration: none;
    transition: background 0.15s;
}
.wizard-welcome-msg:hover {
    background: var(--bg-hover, rgba(0,0,0,.05));
}

/* ── Blazor error UI ─────────────────────────────────────────────────────── */
#blazor-error-ui {
    background: #fff3cd;
    bottom: 0; left: 0;
    box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none;
    padding: 0.6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.admin-container { overflow: auto; }

/* ── Time + toolbar row ──────────────────────────────────────────────────── */
.msg-meta-row {
    display: flex;
    align-items: flex-start;
    gap: 0.375rem;
    margin-top: 0.2rem;
    min-height: 22px;
    width: 100%;
}

/* Toolbar: hidden until message hover, then semi-transparent */
.msg-toolbar {
    display: flex;
    gap: 0.125rem;
    opacity: 0;
    transition: opacity .15s;
}
.message-bot:hover .msg-toolbar,
.msg-toolbar:has(.active),
.msg-toolbar:has(.active-neg) { opacity: 1; }

.msg-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px; height: 22px;
    border-radius: 4px;
    color: var(--text-secondary);
    opacity: 0.65;
    cursor: pointer;
    text-decoration: none;
    transition: opacity .12s, background .12s, color .12s;
    -webkit-user-select: none;
    user-select: none;
}
.msg-toolbar-btn:hover {
    opacity: 1;
    background: var(--bg-surface-2);
    color: var(--text-primary);
}
.msg-toolbar-btn.active     { color: var(--accent); opacity: 1; }
.msg-toolbar-btn.active-neg { color: #e53e3e;        opacity: 1; }

/* Comment box after thumbs-down */
.msg-comment-box { margin-top: 0.5rem; width: 100%; }

.comment-textarea {
    width: 100%;
    resize: none;
    border: 1px solid var(--border-input);
    border-radius: 10px;
    padding: 0.45rem 0.7rem;
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.3;
    outline: none;
    background: var(--bg-surface-2);
    color: var(--text-primary);
    overflow-y: auto;
    scrollbar-width: none;
    field-sizing: content;
    min-height: calc(1.3em + 0.9rem);
    max-height: 100px;
    transition: border-color .15s;
    display: block;
}
.comment-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent);
}
.comment-textarea::placeholder { color: var(--text-secondary); opacity: 1; }

.msg-comment-actions { display: flex; gap: 0.375rem; margin-top: 0.375rem; }

/* ── End Knowledge Graph ──────────────────────────────────────────────────── */

/* ── Report button ──────────────────────────────────────────────────────────── */
.btn-report {
    display: flex; align-items: center; gap: 0.35rem;
    height: 28px;
    padding: 0 0.6rem;
    border-radius: 99px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: color .15s, border-color .15s;
}
.btn-report:hover { color: var(--accent); border-color: var(--accent); }
.btn-report-label { white-space: nowrap; }

@font-face {
    font-family: 'OpenDyslexic';
    src: url('../assets/OpenDyslexic-Regular.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('../assets/OpenDyslexic-Bold.otf') format('opentype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('../assets/OpenDyslexic-Italic.otf') format('opentype');
    font-weight: 400;
    font-style: italic;
    font-display: swap;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('../assets/OpenDyslexic-BoldItalic.otf') format('opentype');
    font-weight: 700;
    font-style: italic;
    font-display: swap;
}

/* ─── Memory Map (Graph.razor) ──────────────────────────────────────────── */
.mm-page {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 1rem 1.25rem 0;
    box-sizing: border-box;
}
.mm-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.5rem;
    flex: 0 0 auto;
}
.mm-title    { margin: 0; font-size: 1.4rem; font-weight: 600; color: var(--text-primary, #1f2937); }
.mm-subtitle { margin: 0.2rem 0 0; font-size: .85rem; color: var(--text-secondary, #6b7280); }
.mm-toolbar-actions { display: flex; gap: .5rem; flex: 0 0 auto; }
.mm-status   { margin: .5rem 0; }
.mm-canvas-wrap {
    flex: 1 1 auto;
    position: relative;
    min-height: 0;
    /* Canvas background tracks the app theme — clusters need to pop against
       either the bright page or the dark page without manual tinting. */
    background: var(--bg-surface-2);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
}
.mm-canvas { position: absolute; inset: 0; }

/* ── Activity heatmap (Memory Map §16) ────────────────────────────────── */
.mm-heatmap {
    display: flex;
    flex-direction: column;
    gap: .45rem;
    margin: .35rem 0 .7rem;
    flex: 0 0 auto;
}
.mm-heatmap-ranges {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem;
    align-items: center;
}
.mm-range-btn {
    background: transparent;
    color: var(--text-secondary, #6b7280);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 999px;
    padding: .18rem .65rem;
    font-size: .78rem;
    line-height: 1.2;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}
.mm-range-btn:hover:not(:disabled) {
    background: var(--bg-surface-2, #f3f4f6);
    color: var(--text-primary, #1f2937);
}
.mm-range-btn.active {
    background: var(--accent-color, #3b82f6);
    color: #fff;
    border-color: transparent;
}
.mm-range-btn:disabled { opacity: .5; cursor: default; }
.mm-range-btn.mm-range-clear {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    color: var(--text-secondary, #6b7280);
}
.mm-range-btn.mm-range-clear:hover {
    color: #dc2626;
    border-color: #fecaca;
}
.mm-heatmap-search {
    margin-left: auto;
    min-width: 160px;
    flex: 0 1 240px;
    padding: .22rem .6rem;
    font-size: .78rem;
    border: 1px solid var(--border-input, #e5e7eb);
    border-radius: 6px;
    background: var(--bg-surface-2);
    color: var(--text-primary);
    outline: none;
}
.mm-heatmap-search::placeholder { color: var(--text-muted); }
.mm-heatmap-search:focus { border-color: var(--accent); }
.mm-range-btn.mm-heatmap-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .18rem .4rem;
}
.mm-heatmap-empty {
    font-size: .78rem;
    color: var(--text-secondary, #6b7280);
    padding: .25rem 0;
}
.mm-heatmap-svg {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}
.mm-axis-label {
    font-size: .5em;
}
.mm-cell {
    cursor: pointer;
    transition: opacity .12s, stroke-width .12s;
    stroke: transparent;
    stroke-width: 0;
    /* Default fill is overridden by level classes below. Light theme. */
    fill: #ebedf0;
}
.mm-cell.empty { fill: #ebedf0; opacity: .55; }
.mm-cell.mm-cell-l0 { fill: #ebedf0; }
.mm-cell.mm-cell-l1 { fill: #c6e48b; }
.mm-cell.mm-cell-l2 { fill: #7bc96f; }
.mm-cell.mm-cell-l3 { fill: #239a3b; }
.mm-cell.mm-cell-l4 { fill: #196127; }
.mm-cell:hover {
    stroke: var(--accent-color, #3b82f6);
    stroke-width: 1.5;
}
.mm-cell.active {
    stroke: #1f2937;
    stroke-width: 2;
}

/* Dark-theme palette */
[data-bs-theme="dark"] .mm-cell,
[data-bs-theme="dark"] .mm-cell.mm-cell-l0 { fill: #2d333b; }
[data-bs-theme="dark"] .mm-cell.empty      { fill: #2d333b; opacity: .55; }
[data-bs-theme="dark"] .mm-cell.mm-cell-l1 { fill: #0e4429; }
[data-bs-theme="dark"] .mm-cell.mm-cell-l2 { fill: #006d32; }
[data-bs-theme="dark"] .mm-cell.mm-cell-l3 { fill: #26a641; }
[data-bs-theme="dark"] .mm-cell.mm-cell-l4 { fill: #39d353; }
[data-bs-theme="dark"] .mm-cell.active     { stroke: #e5e7eb; }

/* Floating popup over the canvas (positioned by memory_map.js near the
   double-clicked node — no sidebar, by design). */
.mm-popup {
    position: absolute;
    z-index: 10;
    width: 280px;
    max-width: 320px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #1f2937);
    border-radius: 8px;
    border: 1px solid var(--border-color, #e5e7eb);
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
    padding: .75rem .9rem .9rem;
    font-size: .85rem;
    pointer-events: auto;
}
.mm-popup-close {
    position: absolute;
    top: 4px; right: 6px;
    background: transparent;
    border: 0;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--text-secondary, #9ca3af);
    cursor: pointer;
    padding: 2px 6px;
}
.mm-popup-close:hover { color: var(--text-primary, #1f2937); }
.mm-popup-kind {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-secondary, #6b7280);
    margin-bottom: .2rem;
}
.mm-popup-title {
    font-weight: 600;
    margin-bottom: .35rem;
    word-break: break-word;
    line-height: 1.25;
}
.mm-popup-meta {
    font-size: .78rem;
    color: var(--text-secondary, #6b7280);
    line-height: 1.45;
    margin-bottom: .55rem;
}
.mm-popup-meta div { margin-bottom: .1rem; }
.mm-popup-body {
    font-size: .82rem;
    color: var(--text-primary, #374151);
    background: var(--bg-secondary, #f3f4f6);
    padding: .45rem .55rem;
    border-radius: 5px;
    margin-bottom: .55rem;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.4;
}
.mm-popup-actions {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    margin-top: .55rem;
}

/* Section block inside the popup (used for chat memory summaries) */
.mm-popup-section { margin-top: .8rem; }
.mm-popup-section h4 {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-secondary, #6b7280);
    margin: 0 0 .35rem;
}
.mm-summaries {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 280px;
    overflow-y: auto;
}
.mm-summaries li {
    padding: .45rem .55rem;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 5px;
    margin-bottom: .35rem;
    background: var(--bg-secondary, #f9fafb);
}
.mm-summary-header { font-weight: 600; font-size: .8rem; color: var(--text-primary, #1f2937); }
.mm-summary-body   { font-size: .77rem; color: var(--text-secondary, #6b7280); margin-top: .15rem; line-height: 1.4; }
.mm-summary-date   { font-size: .7rem;  color: var(--text-secondary, #9ca3af); margin-top: .15rem; }

/* First-chunk preview block on the document popup — italic, indented, gives
   a glance at what's inside the doc without expanding the chunk list. */
.mm-popup-preview-header {
    font-size: .76rem;
    font-weight: 600;
    color: var(--text-primary, #1f2937);
    margin-top: .4rem;
}
.mm-popup-preview-body {
    font-size: .77rem;
    color: var(--text-secondary, #6b7280);
    font-style: italic;
    line-height: 1.4;
    margin-top: .15rem;
    border-left: 2px solid var(--border, #e5e7eb);
    padding-left: .55rem;
}

/* Inline chunk list inside the document popup, rendered after the user
   clicks "Show chunks". Container is empty until then. */
.mm-popup-chunks { margin-top: .55rem; }
.mm-chunk-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 240px;
    overflow-y: auto;
}
.mm-chunk-item {
    padding: .4rem .55rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 5px;
    margin-bottom: .3rem;
    background: var(--bg-surface-2, #f9fafb);
}
.mm-chunk-header { font-weight: 600; font-size: .77rem; color: var(--text-primary, #1f2937); }
.mm-chunk-body   { font-size: .74rem; color: var(--text-secondary, #6b7280); margin-top: .15rem; line-height: 1.35; }

/* ── Object-detail modal ──────────────────────────────────────────────────
   Full-screen overlay that opens when the user clicks "Visualizza" on a
   ref node. Bigger than the popup, so each kind (email/event/task/note/
   contact) can render a rich layout (all headers, body, attachments…).
   Backdrop closes on click; ESC closes; visible "×" close button. */
.mm-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2vh 2vw;
}
.mm-modal {
    position: relative;
    background: var(--bg-surface, #ffffff);
    color: var(--text-primary, #1f2937);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    box-shadow: 0 16px 48px rgba(0,0,0,.45);
    width: min(720px, 96vw);
    max-height: 92vh;
    overflow-y: auto;
    padding: 1.1rem 1.3rem 1.3rem;
}
.mm-modal-close {
    position: absolute;
    top: 6px;
    right: 10px;
    background: transparent;
    border: 0;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.mm-modal-close:hover { background: var(--bg-surface-2, #f3f4f6); color: var(--text-primary, #1f2937); }

.mm-modal-header { margin-bottom: .9rem; }
.mm-modal-kind {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-secondary, #6b7280);
    margin-bottom: .2rem;
}
.mm-modal-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary, #1f2937);
    line-height: 1.3;
    word-wrap: break-word;
}
.mm-modal-meta {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
    margin-bottom: 1rem;
}
.mm-modal-meta th,
.mm-modal-meta td {
    padding: .35rem .55rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.mm-modal-meta th {
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    width: 110px;
    white-space: nowrap;
}
.mm-modal-meta td { word-break: break-word; }

.mm-modal-section { margin-top: 1rem; }
.mm-modal-section-label {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-secondary, #6b7280);
    margin-bottom: .35rem;
}
.mm-modal-body-text {
    margin: 0;
    padding: .7rem .85rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    background: var(--bg-surface-2, #f9fafb);
    font-size: .85rem;
    color: var(--text-primary, #1f2937);
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    max-height: 50vh;
    overflow-y: auto;
}
.mm-modal-empty {
    padding: 1rem;
    font-size: .85rem;
    color: var(--text-secondary, #6b7280);
    font-style: italic;
    text-align: center;
}

/* ─── Node labels (rendered by cytoscape-node-html-label) ──────────────────
   Color-only nodes — text appears below the dot, with type-specific tints.
   Hidden via opacity at low zoom to avoid clutter. */
.mm-node-label {
    font-size: 10px;
    line-height: 1.15;
    padding: 1px 5px;
    margin-top: 4px;
    max-width: 160px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    /* Light theme defaults: dark-grey text on light bg with white halo */
    color: #374151;
    text-shadow: 0 0 3px #ffffff, 0 0 3px #ffffff;
    transition: opacity .25s ease;
}
[data-theme="dark"] .mm-node-label {
    color: #e7eaf2;
    text-shadow: 0 0 3px #0f172a, 0 0 3px #0f172a;
}
.mm-low-zoom .mm-node-label,
.mm-node-hidden { opacity: 0 !important; }
.mm-node-hidden { pointer-events: none; }

/* Slightly emphasize chat & document labels (they're the anchors) */
.mm-node-label-chat,
.mm-node-label-document { font-weight: 600; font-size: 11px; }

/* ─── Settings panel (Memory Map) ─────────────────────────────────────────
   Floating gear button top-right of the canvas; clicking it opens a
   panel anchored to the same corner with three collapsible-style
   sections (filters / appearance / forces). Settings persist via
   GET/PUT /api/auth/ui-preferences/memory_map. */

/* Panel uses the same theme variables as the rest of the app so it
   tracks light/dark automatically. */
.mm-settings-gear {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 12;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: background .15s ease, transform .15s ease, color .15s ease;
}
.mm-settings-gear:hover  { background: var(--bg-surface-2); transform: rotate(30deg); }
.mm-settings-gear:active { transform: rotate(45deg); }

.mm-settings-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 11;
    width: 280px;
    max-height: calc(100% - 24px);
    overflow-y: auto;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    padding: 0;
    font-size: .85rem;
}

.mm-settings-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .7rem .85rem .55rem;
    border-bottom: 1px solid var(--border);
}
.mm-settings-head h3 {
    margin: 0;
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-primary);
}
.mm-settings-head-actions { display: flex; gap: .25rem; }

.mm-icon-btn {
    background: transparent;
    border: 0;
    color: var(--text-secondary);
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.mm-icon-btn:hover { background: var(--bg-surface-2); color: var(--text-primary); }

.mm-settings-section {
    padding: .7rem .85rem;
    border-bottom: 1px solid var(--border);
}
.mm-settings-section:last-of-type { border-bottom: 0; }
.mm-settings-section h4 {
    margin: 0 0 .55rem;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-secondary);
}

.mm-settings-row    { margin-bottom: .45rem; }
.mm-settings-label  { font-size: .72rem; color: var(--text-secondary); margin-bottom: .25rem; }

.mm-settings-search {
    width: 100%;
    background: var(--bg-surface-2);
    color: var(--text-primary);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    padding: .35rem .55rem;
    font-size: .82rem;
    outline: none;
}
.mm-settings-search::placeholder { color: var(--text-muted); }
.mm-settings-search:focus { border-color: var(--accent); }

.mm-toggle-row {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .25rem 0;
}
.mm-toggle-row .mm-toggle-label {
    flex: 1;
    font-size: .82rem;
    color: var(--text-primary);
}
.mm-toggle-row .form-check { padding-left: 0; }
.mm-toggle-row .form-check-input {
    margin-left: 0;
    cursor: pointer;
}
.mm-swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex: 0 0 12px;
    border: 1px solid var(--border);
}

.mm-slider-row {
    margin: .45rem 0 .65rem;
}
.mm-slider-label {
    display: block;
    font-size: .72rem;
    color: var(--text-secondary);
    margin-bottom: .3rem;
}
.mm-slider-row .form-range { width: 100%; }

.mm-radio-row {
    display: flex;
    gap: .9rem;
    margin: .25rem 0 .55rem;
    font-size: .82rem;
    color: var(--text-primary);
}
.mm-radio-row label {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    cursor: pointer;
}
.mm-radio-row input[type=radio] { accent-color: var(--accent); cursor: pointer; }

.mm-rerun-btn {
    width: 100%;
    margin-top: .25rem;
}

.mm-settings-footer {
    padding: .55rem .85rem .7rem;
    border-top: 1px solid var(--border);
}

/* ── Memory v2 — chat ref-bar (links/previews below a reply) ───────────────── */
.ref-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin: .4rem 0 .1rem;
}
.ref-chip {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    max-width: 100%;
    padding: .22rem .55rem;
    font-size: .8rem;
    line-height: 1.2;
    color: var(--accent);
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
    transition: background .12s, border-color .12s;
}
.ref-chip:hover {
    background: var(--bg-surface);
    border-color: var(--accent);
}
.ref-chip-icon  { font-size: .85rem; line-height: 1; }
.ref-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Shared ref-preview modal (chat + graph) ──────────────────────────────── */
.ref-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1080;
    padding: 1rem;
}
.ref-modal {
    position: relative;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: min(640px, 100%);
    max-height: 82vh;
    overflow-y: auto;
    padding: 1.1rem 1.25rem 1.35rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
.ref-modal-close {
    position: absolute;
    top: .5rem;
    right: .6rem;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
}
.ref-modal-close:hover { color: var(--text-primary); }
.ref-modal-loading,
.ref-modal-empty   { padding: 1.5rem .5rem; color: var(--text-muted); text-align: center; }
.ref-modal-header  { margin-bottom: .8rem; padding-right: 1.5rem; }
.ref-modal-kind {
    display: inline-block;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}
.ref-modal-title   { display: block; font-size: 1.1rem; font-weight: 600; margin-top: .15rem; }
.ref-modal-meta    { width: 100%; border-collapse: collapse; font-size: .85rem; }
.ref-modal-meta th {
    text-align: left;
    vertical-align: top;
    width: 7.5rem;
    padding: .25rem .6rem .25rem 0;
    color: var(--text-muted);
    font-weight: 500;
}
.ref-modal-meta td { padding: .25rem 0; word-break: break-word; }
.ref-modal-section       { margin-top: 1rem; }
.ref-modal-section-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: .35rem; }
.ref-modal-body-text {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    font-size: .88rem;
    margin: 0;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .7rem .8rem;
}
.ref-modal-chunk      { margin-bottom: .7rem; padding-bottom: .7rem; border-bottom: 1px solid var(--border); }
.ref-modal-chunk:last-child { border-bottom: none; margin-bottom: 0; }
.ref-modal-chunk-head { font-weight: 600; font-size: .85rem; margin-bottom: .2rem; }
.ref-modal-chunk-body { font-size: .85rem; white-space: pre-wrap; word-break: break-word; color: var(--text-muted); }

/* ── Job Orchestrator (Jobs page) ──────────────────────────────────────────── */
.jobs-empty {
    display: flex; flex-direction: column; align-items: center; gap: .75rem;
    padding: 3rem 1rem; color: var(--text-secondary);
}
.jobs-list { display: flex; flex-direction: column; gap: .6rem; overflow-y: auto; padding-bottom: 1rem; }
.jobs-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.jobs-card.expanded { border-color: var(--accent); }
.jobs-card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; padding: .75rem 1rem; cursor: pointer;
}
.jobs-card-head:hover { background: var(--bg-surface-2); }
.jobs-card-main { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.jobs-card-name { font-weight: 600; color: var(--text-primary); }
.jobs-card-sched { font-size: .8rem; color: var(--text-secondary); }
.jobs-card-meta { display: flex; align-items: center; gap: .75rem; flex: 0 0 auto; }
.jobs-card-body { padding: .25rem 1rem 1rem; border-top: 1px solid var(--border); }
.jobs-actions { display: flex; align-items: center; gap: .5rem; padding: .75rem 0; }

.jobs-dag-wrap { position: relative; }
.jobs-dag {
    height: 280px; width: 100%;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg-surface-2);
}
.jobs-legend {
    display: flex; flex-wrap: wrap; gap: .75rem;
    margin: .5rem 0; font-size: .75rem; color: var(--text-secondary);
}
.jobs-legend span { display: inline-flex; align-items: center; gap: .3rem; }
.jobs-legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.jobs-runs { display: flex; flex-direction: column; gap: .25rem; margin-top: .5rem; }
.jobs-run-row {
    display: flex; align-items: center; gap: .75rem;
    padding: .4rem .6rem; border: 1px solid transparent; border-radius: 6px;
    background: none; text-align: left; cursor: pointer; color: var(--text-primary);
}
.jobs-run-row:hover { background: var(--bg-surface-2); }
.jobs-run-row.active { border-color: var(--accent); background: var(--bg-surface-2); }
.jobs-run-when { font-size: .8rem; }
.jobs-run-trigger { font-size: .72rem; color: var(--text-secondary); margin-left: auto; }

.jobs-modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center; z-index: 1050;
}
.jobs-modal {
    background: var(--bg-surface); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: 12px;
    padding: 1.25rem; width: min(440px, 92vw); max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-lg, 0 10px 40px rgba(0,0,0,.3));
}
.jobs-modal h3 { margin: 0 0 1rem; font-size: 1.15rem; }
.jobs-field-label { display: block; margin: .75rem 0 .25rem; font-size: .8rem; font-weight: 600; color: var(--text-secondary); }
.jobs-template-picker { display: flex; gap: .5rem; flex-wrap: wrap; }
.jobs-template-btn {
    flex: 1 1 0; padding: .5rem .75rem; border: 1px solid var(--border);
    border-radius: 8px; background: var(--bg-surface-2); color: var(--text-primary); cursor: pointer;
}
.jobs-template-btn.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.jobs-modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

/* ── Notification detail modal ─────────────────────────────────────────────── */
.notif-modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center; z-index: 1100;
}
.notif-modal {
    background: var(--bg-surface); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: 12px;
    padding: 1.1rem 1.25rem; width: min(480px, 92vw); max-height: 80vh;
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg, 0 10px 40px rgba(0,0,0,.3));
}
.notif-modal-head { display: flex; align-items: flex-start; gap: 1rem; }
.notif-modal-title { margin: 0; font-size: 1.05rem; font-weight: 600; flex: 1 1 auto; word-break: break-word; }
.notif-modal-close {
    background: none; border: none; font-size: 1.5rem; line-height: 1;
    color: var(--text-secondary); cursor: pointer; padding: 0 .25rem;
}
.notif-modal-close:hover { color: var(--text-primary); }
.notif-modal-meta { font-size: .78rem; color: var(--text-secondary); margin: .35rem 0 .75rem; }
.notif-modal-body {
    font-size: .9rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
    overflow-y: auto; color: var(--text-primary);
}

/* ── Reusable toasts ───────────────────────────────────────────────────────── */
.toast-stack {
    position: fixed; bottom: 1rem; right: 1rem; z-index: 1200;
    display: flex; flex-direction: column; gap: .5rem;
    max-width: min(380px, calc(100vw - 2rem));
    pointer-events: none;
}
.kibo-toast {
    pointer-events: auto;
    display: flex; align-items: flex-start; gap: .6rem;
    background: var(--bg-surface); color: var(--text-primary);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 10px; padding: .7rem .85rem;
    box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,.25));
    animation: kibo-toast-in .22s ease-out;
}
@keyframes kibo-toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
.kibo-toast-icon { font-size: 1rem; line-height: 1.3; flex: 0 0 auto; }
.kibo-toast-content { flex: 1 1 auto; min-width: 0; }
.kibo-toast-title { font-weight: 600; font-size: .85rem; margin-bottom: .15rem; }
.kibo-toast-msg {
    font-size: .82rem; line-height: 1.4; color: var(--text-secondary);
    white-space: pre-wrap; word-break: break-word;
    display: -webkit-box; -webkit-line-clamp: 4; line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.kibo-toast-close {
    background: none; border: none; color: var(--text-secondary);
    font-size: 1.15rem; line-height: 1; cursor: pointer; padding: 0 .15rem; flex: 0 0 auto;
}
.kibo-toast-close:hover { color: var(--text-primary); }

/* Variant accents (left border + icon colour) */
.kibo-toast-info    { border-left-color: #3b82f6; }
.kibo-toast-info    .kibo-toast-icon { color: #3b82f6; }
.kibo-toast-success { border-left-color: #22c55e; }
.kibo-toast-success .kibo-toast-icon { color: #22c55e; }
.kibo-toast-warning { border-left-color: #f59e0b; }
.kibo-toast-warning .kibo-toast-icon { color: #f59e0b; }
.kibo-toast-error   { border-left-color: #ef4444; }
.kibo-toast-error   .kibo-toast-icon { color: #ef4444; }
.kibo-toast-plain   { border-left-color: var(--border); }

