/* ============================================================
   CAMPUSPREP STUDY ASSISTANT — ChatGPT-style widget
   ============================================================ */

/* ============================================================
   LIGHT MODE PALETTE OVERRIDE
   The site's :root variables resolve to near-identical whites in
   light mode (background=100%, secondary=95.9%, accent=95.9%).
   We override them scoped to the assistant shell so the rest of
   the site is untouched.
   ============================================================ */
/* Dark mode: define --popover so hsl(var(--popover)) renders as a visible surface */
.dark #ai-panel-shell {
    --popover:              240 6% 14%;
    --popover-foreground:   0 0% 98%;
}

html:not(.dark) #ai-panel-shell {
    /* Inherit site's --primary (near-black: 240 5.9% 10%) — no override needed.
       Only fix what the site's near-identical whites break inside the widget. */
    --background:           0 0% 99%;
    --foreground:           240 10% 6%;
    --popover:              0 0% 100%;
    --popover-foreground:   240 10% 6%;
    --secondary:            240 5% 92%;
    --secondary-foreground: 240 10% 6%;
    --muted:                240 5% 92%;
    --muted-foreground:     240 5% 32%;   /* boost from site's 46.1% so sidebar text is legible */
    --accent:               240 5% 86%;
    --accent-foreground:    240 10% 6%;
    --border:               240 5.9% 82%;
    --input:                240 5.9% 82%;
    /* --primary / --primary-foreground: inherit site near-black — no override */
}

/* Sidebar — slightly darker than main area so it reads as a panel */
html:not(.dark) #ai-panel-shell #ai-sidebar {
    background: hsl(240 5% 93%);
    border-right-color: hsl(240 5.9% 82%);
}

/* Sidebar text */
html:not(.dark) #ai-panel-shell .ai-sb-sec {
    color: hsl(240 5% 28%);
    letter-spacing: .04em;
}
html:not(.dark) #ai-panel-shell .ai-history-title {
    color: hsl(240 10% 10%);
}
html:not(.dark) #ai-panel-shell .ai-history-meta {
    color: hsl(240 5% 38%);
}

/* User message bubble */
html:not(.dark) #ai-panel-shell .u-bub {
    background: hsl(240 5% 88%);
    color: hsl(240 10% 6%);
}

/* Input area */
html:not(.dark) #ai-panel-shell .ai-iwrap {
    background: hsl(0 0% 100%);
    border-color: hsl(240 5.9% 78%);
}

/* Plain tags (e.g. Dashboard) — neutral chip on light bg */
html:not(.dark) #ai-panel-shell .ai-tag-btn {
    background: hsl(240 5% 86%);
    color: hsl(240 10% 14%);
    border-color: hsl(240 5% 72%);
}
html:not(.dark) #ai-panel-shell .ai-tag-btn:hover {
    background: hsl(240 5% 78%);
    color: hsl(240 10% 6%);
}
html:not(.dark) #ai-panel-shell .ai-tag-btn.is-active {
    background: hsl(240 8% 72%);
    color: hsl(240 10% 5%);
    border-color: hsl(240 8% 58%);
}

/* Colored hash tags — soft tinted chip: light hue bg + dark hue text */
html:not(.dark) #ai-panel-shell .ai-tag-btn.ai-tag-colored {
    background: hsl(var(--ai-hue, 200) 62% 91%);
    color: hsl(var(--ai-hue, 200) 55% 20%);
    border-color: hsl(var(--ai-hue, 200) 45% 74%);
}
html:not(.dark) #ai-panel-shell .ai-tag-btn.ai-tag-colored:hover {
    background: hsl(var(--ai-hue, 200) 62% 84%);
    color: hsl(var(--ai-hue, 200) 60% 14%);
}
html:not(.dark) #ai-panel-shell .ai-tag-btn.ai-tag-colored.is-active {
    background: hsl(var(--ai-hue, 200) 62% 78%);
    color: hsl(var(--ai-hue, 200) 65% 10%);
    border-color: hsl(var(--ai-hue, 200) 50% 60%);
}

/* --- Launcher FAB --- */
#ai-assistant-root {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 9000;
}

/* Brand name in sidebar header — uses foreground so it's readable in both modes */
.ai-brand-name {
    font-size: 14px;
    font-weight: 600;
    color: hsl(var(--foreground));
}

#ai-launcher {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, .55);
    transition: background .15s, transform .15s, box-shadow .15s;
}

#ai-launcher:hover {
    background: hsl(var(--primary) / 0.85);
    transform: scale(1.07);
    box-shadow: 0 6px 28px rgba(0, 0, 0, .65);
}

/* --- Hidden utility --- */
.ai-hidden {
    display: none !important;
}

/* --- Full-screen overlay shell --- */
#ai-panel-shell {
    position: fixed;
    inset: 0;
    z-index: 9100;
    display: flex;
}

/* Backdrop — hidden in full-screen mode */
#ai-sidebar-overlay {
    display: none;
}

/* ============================================================
   AI APP CONTAINER (ChatGPT aesthetic)
   ============================================================ */
#ai-app {
    position: relative;
    z-index: 1;
    display: flex;
    width: 100%;
    height: 100%;
    border-radius: 0;
    overflow: hidden;
    border: none;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    /* Allow text selection everywhere inside the panel */
    user-select: text;
    -webkit-user-select: text;
}

/* Scrollbars inside app */
#ai-app *::-webkit-scrollbar { width: 5px; height: 5px; }
#ai-app *::-webkit-scrollbar-track { background: transparent; }
#ai-app *::-webkit-scrollbar-thumb { background: hsl(var(--border)); border-radius: 3px; }
#ai-app *::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground) / 0.5); }

/* ============================================================
   SIDEBAR
   ============================================================ */
#ai-sidebar {
    width: 260px;
    min-width: 260px;
    background: hsl(var(--background));
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    transition: width .25s ease, min-width .25s ease;
    flex-shrink: 0;
    border-right: 1px solid hsl(var(--border));
}

#ai-sidebar.ai-sb-collapsed {
    width: 0;
    min-width: 0;
}

.ai-sb-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    flex-shrink: 0;
    border-bottom: 1px solid hsl(var(--border));
}
/* Filter button active state — tinted when a filter is applied */
#ai-filter-btn.is-active {
    color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.12);
}

.ai-sb-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 8px;
}

.ai-sb-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 8px 4px;
    padding: 8px 12px;
    background: hsl(var(--secondary));
    border-radius: 10px;
    color: hsl(var(--muted-foreground));
    border: 1px solid hsl(var(--border));
}

.ai-sb-search-wrap input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: hsl(var(--foreground));
    font-size: 14px;
    font-family: inherit;
}

.ai-sb-search-wrap input::placeholder { color: hsl(var(--muted-foreground) / 0.5); }

.ai-sb-toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
    width: calc(100% - 16px);
    box-sizing: border-box;
    padding: 10px 14px;
    font-size: 13px;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    margin: 6px 8px;
    border-radius: 10px;
    transition: background .1s;
}
.ai-sb-toggle-row svg {
    order: 2;
}
.ai-sb-toggle-row span {
    order: 1;
    flex: 1;
    text-align: left;
}

.ai-sb-toggle-row:hover { background: hsl(var(--accent)); }
.ai-sb-toggle-row.is-active {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}
.ai-sb-toggle-row.is-active svg { opacity: 1; }

.ai-sb-sec {
    font-size: 12px;
    font-weight: 600;
    color: hsl(var(--muted-foreground) / 0.6);
    padding: 10px 22px 4px;
    letter-spacing: .04em;
    text-transform: uppercase;
}

/* History item wrapper (holds the nav button + pin action) */
.ai-sb-nav-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
}
.ai-sb-nav-wrap:hover .ai-sb-pin-btn { opacity: 1; }
.ai-sb-pin-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 5px;
    border-radius: 6px;
    color: hsl(var(--muted-foreground) / 0.5);
    transition: opacity .15s, color .15s, background .15s;
    line-height: 1;
    display: flex;
    align-items: center;
    z-index: 1;
}
.ai-sb-pin-btn:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.ai-sb-pin-btn.is-pinned { opacity: 1; color: hsl(var(--primary)); }

/* History items */
.ai-sb-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    color: hsl(var(--muted-foreground));
    font-size: 14px;
    margin: 1px 8px;
    overflow: hidden;
    border: none;
    background: transparent;
    width: calc(100% - 16px);
    text-align: left;
    transition: background .1s;
}

.ai-sb-nav:hover { background: hsl(var(--accent)); }
.ai-sb-nav.is-selected { background: hsl(var(--secondary)); color: hsl(var(--foreground)); }

.ai-history-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0;
    font-size: 14px;
}

.ai-history-meta {
    display: flex;
    gap: 6px;
    font-size: 12px;
    color: hsl(var(--muted-foreground) / 0.6);
    align-items: center;
}

.ai-history-scope {
    font-size: 11px;
    color: hsl(var(--muted-foreground) / 0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
    cursor: default;
}

.ai-history-row1 {
    display: flex;
    align-items: center;
    gap: 5px;
    overflow: hidden;
}
/* Pin indicator: now AFTER the title, so flex-shrink:0 + margin-left:auto */
.ai-pin-indicator {
    flex-shrink: 0;
    margin-left: auto;
    color: hsl(var(--primary));
    opacity: 0.7;
}

/* Inline rename input in history list */
.ai-history-rename-input {
    flex: 1;
    min-width: 0;
    background: hsl(var(--secondary));
    border: 1px solid hsl(var(--primary) / 0.5);
    border-radius: 5px;
    padding: 1px 6px;
    font-size: 13px;
    font-weight: 500;
    color: hsl(var(--foreground));
    outline: none;
    font-family: inherit;
}

/* Inline error / warning rows in chat */
.ai-error-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 8px auto;
    max-width: 640px;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 13.5px;
    line-height: 1.5;
    border: 1px solid;
}
.ai-error-row--warn {
    background: hsl(38 92% 12%);
    border-color: hsl(38 92% 35% / .6);
    color: hsl(38 95% 70%);
}
.ai-error-row--error {
    background: hsl(0 72% 12%);
    border-color: hsl(0 72% 35% / .6);
    color: hsl(0 80% 70%);
}
.ai-error-row-icon {
    flex-shrink: 0;
    margin-top: 1px;
    opacity: .85;
}
.ai-error-row-text { flex: 1; }

/* ============================================================
   MAIN AREA
   ============================================================ */
#ai-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ---- HEADER ---- */
#ai-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    flex-shrink: 0;
    border-bottom: 1px solid hsl(var(--border));
    position: relative;
    gap: 8px;
    overflow: visible;   /* allow dropdown menus to escape */
    min-height: 54px;
}

.ai-hdr-model {
    font-size: 15px;
    font-weight: 600;
    color: hsl(var(--foreground));
    padding: 0 4px;
    white-space: nowrap;
}

/* Icon button (hamburger, close, 3-dot) */
.ai-ib {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    color: hsl(var(--muted-foreground));
    border: none;
    background: transparent;
    flex-shrink: 0;
    transition: background .1s, color .1s;
}

.ai-ib:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }

/* Context menu — fixed-position so it escapes any overflow:hidden ancestor */
.ai-ctx {
    position: fixed;
    background: hsl(var(--popover) / .98);
    border: 1px solid hsl(var(--border) / .95);
    border-radius: 16px;
    padding: 8px;
    min-width: 200px;
    z-index: 9200;
    box-shadow: 0 18px 44px rgba(0, 0, 0, .52);
}

/* Model picker dropdown */
#ai-model-menu {
    min-width: 280px;
    max-height: 380px;
    overflow-y: auto;
    padding: 8px;
}

/* Model picker trigger button */
.ai-model-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: hsl(var(--foreground));
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .1s;
    font-family: inherit;
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-model-btn:hover { background: hsl(var(--accent)); }
.ai-model-btn svg { flex-shrink: 0; color: hsl(var(--muted-foreground)); }

/* ── Scope pill ── */
.ai-scope-pill {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 9px;
    border-radius: 20px;
    border: 1px solid hsl(var(--border));
    background: hsl(var(--muted) / .6);
    color: hsl(var(--muted-foreground));
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    font-family: inherit;
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-scope-pill:hover,
.ai-scope-pill[aria-expanded="true"] {
    background: hsl(var(--accent));
    border-color: hsl(var(--ring) / .4);
    color: hsl(var(--foreground));
}
.ai-scope-pill #ai-scope-pill-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 130px;
}

/* Mobile: narrower scope pill to prevent layout shift */
@media (max-width: 640px) {
    .ai-scope-pill {
        max-width: 120px;
        padding: 4px 7px;
    }
    .ai-scope-pill #ai-scope-pill-label {
        max-width: 80px;
    }
}

/* Scope picker dropdown — opens upward from footer pill */
.ai-scope-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    top: auto;
    left: 0;
    width: 260px;
    max-width: 260px;
    max-height: 340px;
    overflow-y: auto;
    padding: 6px;
    z-index: 9300;
}
.ai-scope-menu-hdr {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: hsl(var(--muted-foreground) / .7);
    padding: 8px 10px 4px;
}
.ai-scope-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
    padding: 9px 10px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: hsl(var(--foreground));
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    overflow: hidden;
    transition: background .1s;
}
.ai-scope-opt:hover { background: hsl(var(--accent)); }
.ai-scope-opt.is-active {
    background: hsl(var(--primary) / .1);
    color: hsl(var(--primary));
    font-weight: 600;
}
.ai-scope-opt-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 6px;
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    flex-shrink: 0;
    margin-left: auto;
}

/* Provider group header inside model menu */
.ai-model-group-hdr {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: hsl(var(--muted-foreground) / .72);
    padding: 10px 10px 6px;
}

/* Individual model option */
.ai-model-opt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 10px 10px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: hsl(var(--foreground) / .88);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: background .1s, color .1s;
    font-family: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-model-opt:hover { background: hsl(var(--accent) / .9); color: hsl(var(--accent-foreground)); }

.ai-model-opt.is-active {
    background: hsl(var(--accent) / .95);
    color: hsl(var(--accent-foreground));
}

.ai-model-opt .ai-check {
    flex-shrink: 0;
    color: hsl(var(--foreground));
    opacity: 0;
}

.ai-model-opt.is-active .ai-check { opacity: 1; }

.ai-ci {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    color: hsl(var(--foreground) / .92);
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    transition: background .1s;
    font-family: inherit;
}

.ai-ci:hover { background: hsl(var(--accent) / .9); color: hsl(var(--accent-foreground)); }
.ai-ci.is-active { background: hsl(var(--accent) / .95); color: hsl(var(--accent-foreground)); }
.ai-ci svg { color: hsl(var(--muted-foreground) / .92); flex-shrink: 0; }
.ai-ci-red { color: #f87171; }
.ai-ci-red svg { color: #f87171; }

.ai-csep { height: 1px; background: hsl(var(--border)); margin: 4px 0; }

/* Scope breadcrumbs */
.ai-scope-breadcrumbs {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    flex-wrap: nowrap;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.ai-scope-breadcrumbs::-webkit-scrollbar { display: none; }

/* Chat meta strip */
.ai-chat-meta {
    padding: 4px 14px 0;
    flex-shrink: 0;
    min-height: 0;
}

/* Active subject filter bar */
.ai-active-filter {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    margin: 2px 8px 4px;
    background: hsl(var(--primary) / 0.08);
    border: 1px solid hsl(var(--primary) / 0.2);
    border-radius: 8px;
    font-size: 12px;
    color: hsl(var(--foreground));
}
.ai-active-filter-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-active-filter-clear {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    color: hsl(var(--muted-foreground));
    padding: 0 2px;
    border-radius: 4px;
    transition: color .1s;
}
.ai-active-filter-clear:hover { color: hsl(var(--foreground)); }

/* Filter / scope tag buttons */
.ai-filter-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 14px;
}

.ai-tag-btn {
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid hsl(var(--border));
    background: transparent;
    color: hsl(var(--muted-foreground));
    font-size: 12px;
    cursor: pointer;
    transition: background .1s, color .1s;
    white-space: nowrap;
    font-family: inherit;
    flex-shrink: 0;
}

.ai-tag-btn:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.ai-tag-btn.is-active { background: hsl(var(--secondary)); color: hsl(var(--foreground)); border-color: hsl(var(--muted-foreground) / 0.5); }

/* Hash-colored scope tags */
.ai-tag-btn.ai-tag-colored {
    background: hsl(var(--ai-hue, 200) 70% 50% / 0.1);
    color: hsl(var(--ai-hue, 200) 75% 72%);
    border-color: hsl(var(--ai-hue, 200) 60% 50% / 0.3);
}
.ai-tag-btn.ai-tag-colored:hover {
    background: hsl(var(--ai-hue, 200) 70% 50% / 0.2);
    color: hsl(var(--ai-hue, 200) 80% 85%);
}
.ai-tag-btn.ai-tag-colored.is-active {
    background: hsl(var(--ai-hue, 200) 70% 50% / 0.22);
    border-color: hsl(var(--ai-hue, 200) 60% 55% / 0.6);
    color: hsl(var(--ai-hue, 200) 85% 88%);
}

/* Smaller tag variant for sidebar history */
.ai-tag-mini {
    padding: 2px 7px;
    font-size: 11px;
    border-radius: 12px;
    cursor: pointer;
    user-select: none;
}

/* Path separator between breadcrumb chips */
.ai-tag-sep {
    color: hsl(var(--muted-foreground) / 0.4);
    font-size: 13px;
    flex-shrink: 0;
    padding: 0 1px;
    pointer-events: none;
}

/* ============================================================
   MESSAGE LIST
   ============================================================ */
#ai-message-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 0;
    /* Explicitly allow text selection inside the message list */
    user-select: text !important;
    -webkit-user-select: text !important;
}

/* Center messages within the wide layout like ChatGPT */
#ai-message-list > * {
    max-width: 800px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

/* User message */
.u-row {
    display: flex;
    justify-content: flex-end;
    margin: 8px 0 2px;
}

.u-bub {
    background: hsl(var(--secondary));
    border-radius: 18px;
    padding: 10px 16px;
    max-width: 80%;
    font-size: 15px;
    line-height: 1.55;
    word-break: break-word;
    color: hsl(var(--foreground));
    user-select: text;
    -webkit-user-select: text;
    cursor: text;
}
.u-bub > span { white-space: pre-wrap; }

/* Attachment row inside user bubble */
.u-bub-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
.u-bub-thumb {
    width: 120px;
    height: 90px;
    object-fit: cover;
    border-radius: 10px;
    display: block;
    cursor: zoom-in;
    border: 1px solid hsl(var(--border) / .5);
}
.u-bub-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: hsl(var(--muted) / .4);
    border: 1px solid hsl(var(--border) / .5);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 12px;
    max-width: 200px;
    min-width: 0;
}
.u-bub-file-badge {
    flex-shrink: 0;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .04em;
    line-height: 1.6;
}
.u-bub-file-badge.badge-pdf { background: hsl(0 68% 44%); color: #fff; }
.u-bub-file-badge.badge-txt { background: hsl(213 55% 44%); color: #fff; }
.u-bub-file-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: hsl(var(--foreground) / .8);
}

/* Assistant message */
.a-row {
    display: flex;
    gap: 10px;
    margin: 8px 0 2px;
    align-items: flex-start;
}

.a-logo {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
    color: #000;
}

.a-body {
    flex: 1;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
    user-select: text !important;
    -webkit-user-select: text !important;
    cursor: text;
}

.a-body p {
    font-size: 15px;
    line-height: 1.65;
    color: hsl(var(--foreground));
    margin: 0 0 8px;
    word-break: break-word;
}

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

/* ── Toast notifications ── */
/* Mounted inside #ai-panel-shell which is position:fixed, so absolute works */
.ai-toast {
    position: absolute;
    bottom: 88px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    background: hsl(var(--popover));
    color: hsl(var(--popover-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: 10px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    max-width: calc(100% - 32px);
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 4px 24px rgba(0,0,0,.3);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}
.ai-toast.ai-toast-in { opacity: 1; transform: translateX(-50%) translateY(0); }
.ai-toast.ai-toast-warn {
    background: hsl(38 92% 12%);
    border-color: hsl(38 92% 40% / .6);
    color: hsl(38 95% 70%);
}
.ai-toast.ai-toast-error {
    background: hsl(0 72% 12%);
    border-color: hsl(0 72% 40% / .6);
    color: hsl(0 80% 70%);
}
.ai-toast.ai-toast-success {
    background: hsl(142 50% 12%);
    border-color: hsl(142 60% 35% / .6);
    color: hsl(142 70% 60%);
}

/* ── Share dialog ── */
.ai-share-dialog {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(.98);
    background: hsl(var(--popover) / .98);
    border: 1px solid hsl(var(--border) / .95);
    border-radius: 16px;
    width: 360px;
    max-width: calc(100% - 28px);
    box-shadow: 0 18px 44px rgba(0, 0, 0, .52);
    z-index: 9200;
    opacity: 0;
    overflow: hidden;
    transition: opacity .18s ease, transform .18s ease;
}
.ai-share-dialog.ai-share-dialog-in {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}
.ai-sdlg-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 10px;
    border-bottom: 1px solid hsl(var(--border) / .65);
}
.ai-sdlg-title {
    font-size: 14px;
    font-weight: 700;
    color: hsl(var(--foreground));
}
.ai-sdlg-close {
    background: none;
    border: none;
    color: hsl(var(--muted-foreground));
    font-size: 18px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
}
.ai-sdlg-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.ai-sdlg-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    padding: 10px 12px;
    border-radius: 10px;
}
.ai-sdlg-public {
    background: hsl(var(--accent) / .6);
    color: hsl(var(--foreground));
    border: 1px solid hsl(var(--border));
}
.ai-sdlg-private {
    background: hsl(var(--secondary));
    color: hsl(var(--foreground) / .85);
    border: 1px solid hsl(var(--border));
}
.ai-sdlg-url-row {
    display: flex;
    gap: 6px;
}
.ai-sdlg-url-input {
    flex: 1;
    min-width: 0;
    background: hsl(var(--secondary));
    border: 1px solid hsl(var(--border));
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 12px;
    color: hsl(var(--foreground) / .85);
    outline: none;
}
.ai-sdlg-copy-btn {
    flex-shrink: 0;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
    white-space: nowrap;
}
.ai-sdlg-copy-btn:hover { opacity: .85; }
.ai-sdlg-toggle-btn {
    background: hsl(var(--secondary));
    color: hsl(var(--foreground));
    border: 1px solid hsl(var(--border));
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s;
    text-align: center;
}
.ai-sdlg-toggle-btn:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.ai-sdlg-toggle-btn.ai-sdlg-toggle-primary {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border-color: transparent;
}
.ai-sdlg-toggle-btn.ai-sdlg-toggle-primary:hover { opacity: .88; }
.ai-sdlg-toggle-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Attachment previews (ChatGPT-style) ── */
@keyframes ai-spin { to { transform: rotate(360deg); } }

.ai-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 4px 0 10px;
}

/* ── Image lightbox ── */
#ai-img-lightbox {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0,0,0,.85);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}
#ai-img-lightbox.is-open {
    opacity: 1;
    pointer-events: all;
}
#ai-img-lightbox img {
    max-width: min(90vw, 900px);
    max-height: 85vh;
    border-radius: 10px;
    box-shadow: 0 24px 64px rgba(0,0,0,.6);
    transform: scale(.95);
    transition: transform .2s ease;
}
#ai-img-lightbox.is-open img { transform: scale(1); }
#ai-img-lightbox-close {
    position: fixed;
    top: 18px;
    right: 22px;
    background: rgba(255,255,255,.12);
    border: none;
    color: #fff;
    font-size: 22px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background .15s;
}
#ai-img-lightbox-close:hover { background: rgba(255,255,255,.25); }

.ai-attach-item {
    position: relative;
    flex-shrink: 0;
}

/* × button — absolute circle, top-right corner, same for all chips */
.ai-attach-remove {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: hsl(var(--popover));
    border: 1.5px solid hsl(var(--border));
    color: hsl(var(--muted-foreground));
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: background .15s, color .15s;
    z-index: 2;
}
.ai-attach-remove:hover {
    background: hsl(var(--border));
    color: hsl(var(--foreground));
}

/* ── Image chip ── */
.ai-attach-item.is-image {
    width: 68px;
    height: 68px;
    border-radius: 10px;
    border: 1px solid hsl(var(--border));
    background: hsl(var(--secondary));
    overflow: visible;
}
.ai-attach-thumb {
    width: 68px;
    height: 68px;
    object-fit: cover;
    display: block;
    border-radius: 9px;
    cursor: zoom-in;
}
/* Image loading spinner */
.ai-attach-item.is-image.is-loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── File chip ── */
.ai-attach-item.is-file {
    display: flex;
    align-items: center;
    gap: 10px;
    background: hsl(var(--secondary));
    border: 1px solid hsl(var(--border));
    border-radius: 12px;
    padding: 10px 38px 10px 10px;
    min-width: 150px;
    max-width: 230px;
}

/* Coloured square badge (left of file chip) */
.ai-attach-file-badge {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-attach-file-badge.badge-pdf { background: hsl(0 68% 44%); color: #fff; }
.ai-attach-file-badge.badge-txt { background: hsl(213 55% 44%); color: #fff; }

/* Two-line text inside file chip */
.ai-attach-file-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.ai-attach-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 500;
    color: hsl(var(--foreground) / .9);
}
.ai-attach-type {
    font-size: 11px;
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* Loading spinner */
.ai-attach-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid hsl(var(--border));
    border-top-color: hsl(var(--foreground) / .7);
    border-radius: 50%;
    animation: ai-spin .65s linear infinite;
    flex-shrink: 0;
}
/* Smaller spinner inside coloured badge */
.ai-attach-file-badge .ai-attach-spinner {
    width: 16px;
    height: 16px;
    border-color: rgba(255,255,255,.3);
    border-top-color: #fff;
}
.ai-attach-item.is-loading { opacity: .75; }

/* ── Settings panel ── */
/* ═══════════════════════════════════════════════════════════════════
   AI SETTINGS MODAL  (full-screen overlay, tabbed)
   ═══════════════════════════════════════════════════════════════════ */

/* Backdrop */
.ai-settings-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .62);
    backdrop-filter: blur(4px);
    z-index: 9190;
    opacity: 0;
    transition: opacity .22s ease;
}
.ai-settings-backdrop.ai-settings-backdrop-in { opacity: 1; }

/* Dialog */
.ai-settings-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -46%) scale(.96);
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border) / .8);
    border-radius: 20px;
    width: min(680px, calc(100% - 24px));
    max-height: min(88vh, 680px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 40px 100px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.06);
    z-index: 9200;
    opacity: 0;
    transition: opacity .22s ease, transform .22s cubic-bezier(.34,1.4,.64,1);
    overflow: hidden;
}
.ai-settings-panel.ai-settings-panel-in {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* Loading state */
.ai-settings-loading {
    padding: 48px 24px;
    font-size: 13px;
    color: hsl(var(--muted-foreground));
    text-align: center;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Header ── */
.ai-settings-hdr {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px 0;
    flex-shrink: 0;
}
.ai-settings-icon {
    width: 32px; height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, hsl(var(--primary) / .15), hsl(var(--primary) / .3));
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    color: hsl(var(--primary));
}
.ai-settings-titles { flex: 1; min-width: 0; }
.ai-settings-title {
    font-size: 15px;
    font-weight: 700;
    color: hsl(var(--foreground));
    display: block;
}
.ai-settings-subtitle {
    font-size: 11.5px;
    color: hsl(var(--muted-foreground));
    display: block;
    margin-top: 1px;
}
.ai-settings-close {
    background: hsl(var(--secondary));
    border: none;
    width: 28px; height: 28px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: hsl(var(--muted-foreground));
    flex-shrink: 0;
    transition: background .15s, color .15s;
    font-size: 16px; line-height: 1;
}
.ai-settings-close:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }

/* ── Tabs ── */
.ai-settings-tabs {
    display: flex;
    gap: 2px;
    padding: 12px 20px 0;
    border-bottom: 1px solid hsl(var(--border) / .6);
    flex-shrink: 0;
}
.ai-stab {
    padding: 7px 14px;
    font-size: 12.5px;
    font-weight: 500;
    border: none;
    background: none;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    border-radius: 8px 8px 0 0;
    position: relative;
    transition: color .15s, background .15s;
    display: flex; align-items: center; gap: 5px;
    white-space: nowrap;
}
.ai-stab:hover { color: hsl(var(--foreground)); background: hsl(var(--accent) / .5); }
.ai-stab.active {
    color: hsl(var(--foreground));
    font-weight: 600;
}
.ai-stab.active::after {
    content: '';
    position: absolute;
    bottom: -1px; left: 0; right: 0;
    height: 2px;
    background: hsl(var(--primary));
    border-radius: 2px 2px 0 0;
}
.ai-stab-badge {
    background: hsl(var(--primary) / .18);
    color: hsl(var(--primary));
    border-radius: 99px;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    min-width: 18px;
    text-align: center;
}

/* ── Body / Scroll ── */
.ai-settings-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 20px 4px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scrollbar-width: thin;
}
.ai-settings-body::-webkit-scrollbar { width: 4px; }
.ai-settings-body::-webkit-scrollbar-thumb { background: hsl(var(--border)); border-radius: 4px; }

/* ── Sticky save footer (prefs tab) ── */
.ai-settings-footer {
    flex-shrink: 0;
    display: none;               /* shown only when prefs tab is active */
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 20px 16px;
    border-top: 1px solid hsl(var(--border) / .6);
    background: hsl(var(--background));
    border-radius: 0 0 20px 20px;
}
.ai-settings-footer.visible { display: flex; }

/* Tab panes */
.ai-settings-pane { display: none; flex-direction: column; gap: 20px; }
.ai-settings-pane.active { display: flex; }

/* ── Section ── */
.ai-settings-sec {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ai-settings-sec-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: hsl(var(--muted-foreground) / .72);
}
.ai-settings-hint {
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    margin: 0;
    line-height: 1.5;
}

/* ── Chip selectors (language / style / tone) ── */
.ai-chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.ai-chip {
    padding: 6px 13px;
    border-radius: 99px;
    border: 1.5px solid hsl(var(--border));
    background: hsl(var(--secondary) / .6);
    color: hsl(var(--foreground) / .75);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    user-select: none;
}
.ai-chip:hover {
    border-color: hsl(var(--primary) / .5);
    background: hsl(var(--primary) / .08);
    color: hsl(var(--foreground));
}
.ai-chip.selected {
    border-color: hsl(var(--primary));
    background: hsl(var(--primary) / .15);
    color: hsl(var(--primary));
    font-weight: 600;
}

/* ── Text areas ── */
.ai-settings-textarea {
    width: 100%;
    box-sizing: border-box;
    background: hsl(var(--secondary) / .5);
    border: 1.5px solid hsl(var(--border));
    border-radius: 10px;
    color: hsl(var(--foreground));
    font-size: 13px;
    font-family: inherit;
    padding: 10px 12px;
    resize: vertical;
    min-height: 72px;
    max-height: 180px;
    line-height: 1.5;
    transition: border-color .15s, background .15s;
}
.ai-settings-textarea:focus {
    outline: none;
    border-color: hsl(var(--primary) / .6);
    background: hsl(var(--background));
}
.ai-settings-char-count {
    font-size: 11px;
    color: hsl(var(--muted-foreground) / .6);
    text-align: right;
    margin-top: 2px;
}
.ai-settings-save-row { display: none; }   /* replaced by sticky footer */

.ai-settings-save-btn {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
    border-radius: 10px;
    padding: 9px 22px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s, transform .1s, box-shadow .2s;
    display: flex; align-items: center; gap: 6px;
    white-space: nowrap;
}
.ai-settings-save-btn:hover { opacity: .88; }
.ai-settings-save-btn:active { transform: scale(.97); }
.ai-settings-save-btn:disabled { opacity: .45; cursor: not-allowed; }

/* Pulse ring when there are unsaved changes */
@keyframes ai-dirty-pulse {
    0%, 100% { box-shadow: 0 0 0 0 hsl(var(--primary) / .55); }
    50%       { box-shadow: 0 0 0 6px hsl(var(--primary) / 0); }
}
.ai-settings-save-btn.dirty {
    animation: ai-dirty-pulse 1.8s ease-in-out infinite;
}

/* ── Memories ── */
.ai-mem-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.ai-mem-add-btn {
    display: flex; align-items: center; gap: 5px;
    background: hsl(var(--primary) / .12);
    color: hsl(var(--primary));
    border: 1.5px solid hsl(var(--primary) / .3);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.ai-mem-add-btn:hover { background: hsl(var(--primary) / .2); border-color: hsl(var(--primary) / .6); }

.ai-mem-empty {
    text-align: center;
    padding: 36px 20px;
    color: hsl(var(--muted-foreground));
    font-size: 13px;
}
.ai-mem-empty svg { opacity: .3; margin-bottom: 10px; display: block; margin-left: auto; margin-right: auto; }

.ai-mem-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ai-mem-card {
    background: hsl(var(--secondary) / .5);
    border: 1px solid hsl(var(--border) / .8);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    transition: border-color .15s, background .15s;
    position: relative;
}
.ai-mem-card:hover { border-color: hsl(var(--border)); background: hsl(var(--secondary) / .7); }
.ai-mem-card.disabled { opacity: .45; }
.ai-mem-card-top {
    display: flex; align-items: flex-start; gap: 8px;
}
.ai-mem-card-title {
    flex: 1; font-size: 13px; font-weight: 600;
    color: hsl(var(--foreground));
    line-height: 1.4;
    min-width: 0;
}
.ai-mem-card-content {
    font-size: 12.5px; color: hsl(var(--muted-foreground));
    line-height: 1.5;
}
.ai-mem-card-footer {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    margin-top: 2px;
}
.ai-mem-cat-badge {
    font-size: 10.5px; font-weight: 600;
    padding: 2px 8px; border-radius: 99px;
    background: hsl(var(--primary) / .12);
    color: hsl(var(--primary));
    text-transform: capitalize;
    letter-spacing: .02em;
}
.ai-mem-source-badge {
    font-size: 10.5px;
    color: hsl(var(--muted-foreground) / .7);
    display: flex; align-items: center; gap: 3px;
}
.ai-mem-actions {
    display: flex; gap: 3px; align-items: center; flex-shrink: 0;
    margin-left: auto;
}
.ai-mem-action-btn {
    background: none; border: none;
    width: 28px; height: 28px;
    border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: hsl(var(--muted-foreground));
    transition: background .12s, color .12s;
}
.ai-mem-action-btn:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.ai-mem-action-btn.delete:hover { background: hsl(0 60% 15%); color: hsl(0 70% 65%); }
.ai-mem-toggle-btn {
    background: none; border: none;
    font-size: 11px; font-weight: 500;
    color: hsl(var(--muted-foreground));
    cursor: pointer; padding: 0;
    margin-left: auto;
    transition: color .12s;
}
.ai-mem-toggle-btn:hover { color: hsl(var(--foreground)); }

/* Memory inline edit form */
.ai-mem-edit-form {
    display: flex; flex-direction: column; gap: 8px;
    margin-top: 6px; padding-top: 10px;
    border-top: 1px solid hsl(var(--border) / .5);
}
.ai-mem-edit-input {
    background: hsl(var(--background));
    border: 1.5px solid hsl(var(--border));
    border-radius: 8px;
    color: hsl(var(--foreground));
    font-size: 12.5px;
    font-family: inherit;
    padding: 7px 10px;
    width: 100%; box-sizing: border-box;
    transition: border-color .12s;
}
.ai-mem-edit-input:focus { outline: none; border-color: hsl(var(--primary) / .6); }
.ai-mem-edit-textarea {
    background: hsl(var(--background));
    border: 1.5px solid hsl(var(--border));
    border-radius: 8px;
    color: hsl(var(--foreground));
    font-size: 12.5px;
    font-family: inherit;
    padding: 7px 10px;
    width: 100%; box-sizing: border-box;
    resize: vertical; min-height: 54px;
    transition: border-color .12s;
}
.ai-mem-edit-textarea:focus { outline: none; border-color: hsl(var(--primary) / .6); }
.ai-mem-edit-cat-select {
    background: hsl(var(--background));
    border: 1.5px solid hsl(var(--border));
    border-radius: 8px;
    color: hsl(var(--foreground));
    font-size: 12.5px;
    font-family: inherit;
    padding: 6px 10px;
    width: 100%; box-sizing: border-box;
    transition: border-color .12s;
}
.ai-mem-edit-cat-select:focus { outline: none; border-color: hsl(var(--primary) / .6); }
.ai-mem-edit-btns {
    display: flex; gap: 6px; justify-content: flex-end;
}
.ai-mem-edit-save {
    background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
    border: none; border-radius: 7px; padding: 6px 14px;
    font-size: 12px; font-weight: 600; cursor: pointer;
    transition: opacity .15s;
}
.ai-mem-edit-save:hover { opacity: .85; }
.ai-mem-edit-cancel {
    background: hsl(var(--secondary)); color: hsl(var(--foreground));
    border: none; border-radius: 7px; padding: 6px 12px;
    font-size: 12px; cursor: pointer;
    transition: background .15s;
}
.ai-mem-edit-cancel:hover { background: hsl(var(--accent)); }

/* ── Storage & credits ── */
.ai-settings-storage-row {
    display: flex;
    justify-content: space-between;
    font-size: 12.5px;
    color: hsl(var(--foreground));
    align-items: center;
}
.ai-settings-pct {
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    background: hsl(var(--secondary));
    border-radius: 6px;
    padding: 2px 7px;
}
.ai-settings-bar-track {
    height: 6px;
    background: hsl(var(--secondary));
    border-radius: 99px;
    overflow: hidden;
}
.ai-settings-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, hsl(var(--primary)), hsl(var(--primary) / .7));
    border-radius: 99px;
    transition: width .4s ease;
}
.ai-settings-del-all-btn {
    background: hsl(0 60% 15%);
    color: hsl(0 70% 65%);
    border: 1px solid hsl(0 50% 30% / .5);
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s;
    align-self: flex-start;
}
.ai-settings-del-all-btn:hover { background: hsl(0 60% 20%); }
.ai-settings-del-all-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Credits card */
.ai-credits-card {
    background: linear-gradient(135deg, hsl(var(--primary) / .08), hsl(var(--primary) / .04));
    border: 1px solid hsl(var(--primary) / .2);
    border-radius: 12px;
    padding: 14px 16px;
    display: flex; gap: 12px; align-items: center;
}
.ai-credits-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: hsl(var(--primary) / .15);
    display: flex; align-items: center; justify-content: center;
    color: hsl(var(--primary)); flex-shrink: 0;
}
.ai-credits-info { flex: 1; min-width: 0; }
.ai-credits-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: hsl(var(--muted-foreground) / .7); }
.ai-credits-value { font-size: 20px; font-weight: 700; color: hsl(var(--foreground)); margin-top: 2px; }
.ai-credits-sub { font-size: 11.5px; color: hsl(var(--muted-foreground)); margin-top: 1px; }

/* Auto-save indicator */
.ai-settings-saved-indicator {
    font-size: 11px; color: hsl(142 70% 45%);
    display: flex; align-items: center; gap: 4px;
    opacity: 0; transition: opacity .3s;
}
.ai-settings-saved-indicator.show { opacity: 1; }



.ai-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .56);
    backdrop-filter: blur(2px);
    z-index: 9150;
}


/* ── Message action bar ── */
.ai-msg-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity .15s;
    flex-wrap: wrap;
}

.a-row:hover .ai-msg-actions,
.u-row:hover .ai-msg-actions,
.ai-msg-actions:focus-within {
    opacity: 1;
}

.ai-msg-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 7px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: hsl(var(--muted-foreground));
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: background .1s, color .1s, border-color .1s;
    white-space: nowrap;
}

.ai-msg-action:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
    border-color: hsl(var(--border));
}

.ai-msg-action.is-copied {
    color: hsl(142 70% 55%);
}

/* Branch navigator  < 1/2 > */
.ai-branch-nav {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    color: hsl(var(--muted-foreground));
    font-size: 12px;
    user-select: none;
}

.ai-branch-nav span {
    min-width: 28px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* User message edit wrapper */
.u-row-inner {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    max-width: 80%;
}

/* Empty / auth states */
.ai-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px 20px;
    color: hsl(var(--muted-foreground));
    gap: 8px;
}

.ai-empty-title {
    font-size: 16px;
    font-weight: 600;
    color: hsl(var(--foreground));
    margin: 0;
}

.ai-empty-copy {
    font-size: 14px;
    color: hsl(var(--muted-foreground));
    max-width: 380px;
    margin: 0;
}

.ai-auth-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px;
    text-align: center;
}

/* Primary / secondary action buttons */
.ai-primary-btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    font-family: inherit;
}

.ai-primary-btn:hover { background: hsl(var(--primary) / 0.85); }

/* ============================================================
   INPUT BAR
   ============================================================ */
#ai-input-wrapper {
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

#ai-ibar {
    padding: 10px 16px 6px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.ai-iwrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: hsl(var(--secondary));
    border-radius: 16px;
    padding: 10px 12px;
    border: 1px solid hsl(var(--border));
    transition: border-color .15s;
}

.ai-iwrap:focus-within { border-color: hsl(var(--muted-foreground) / 0.5); }

#ai-chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: hsl(var(--foreground));
    font-size: 15px;
    resize: none;
    line-height: 1.5;
    max-height: 160px;
    min-height: 24px;
    font-family: inherit;
    padding: 0;
    vertical-align: middle;
}

#ai-chat-input::placeholder { color: hsl(var(--muted-foreground) / 0.5); }

.ai-iright {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}

.ai-micbtn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    color: hsl(var(--muted-foreground));
    border: none;
    background: transparent;
    transition: color .1s;
}

.ai-micbtn:hover { color: hsl(var(--foreground)); }
.ai-micbtn:disabled { cursor: not-allowed; opacity: .35; }
.ai-micbtn.is-active {
    color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.1);
}
/* Voice button pulses red while recording */
#ai-voice-btn.is-active {
    color: hsl(0 70% 55%);
    background: hsl(0 70% 55% / 0.12);
    animation: ai-voice-pulse 1.2s ease-in-out infinite;
}
@keyframes ai-voice-pulse {
    0%, 100% { background: hsl(0 70% 55% / 0.12); }
    50%       { background: hsl(0 70% 55% / 0.28); }
}

/* Retry button inside a stream-error bubble */
.ai-retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid hsl(var(--border));
    background: hsl(var(--muted) / 0.5);
    color: hsl(var(--muted-foreground));
    font-size: 12px;
    cursor: pointer;
    transition: background .1s, color .1s;
}
.ai-retry-btn:hover {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
}

/* ── Tool call trace (Deep Explore) ───────────────────────────────────────── */
.ai-tool-trace {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.ai-tool-step {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    padding: 3px 8px 3px 6px;
    border-radius: 20px;
    background: hsl(var(--muted) / 0.5);
    width: fit-content;
    max-width: 100%;
}

.ai-tool-step-icon::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border: 2px solid hsl(var(--primary) / 0.6);
    border-top-color: transparent;
    border-radius: 50%;
    animation: ai-tool-spin 0.7s linear infinite;
    flex-shrink: 0;
}

.ai-tool-step.is-done .ai-tool-step-icon::before {
    content: '✓';
    font-size: 10px;
    font-weight: 700;
    color: hsl(142 55% 45%);
    border: none;
    animation: none;
    width: auto;
    height: auto;
}

.ai-tool-step.is-done {
    color: hsl(var(--muted-foreground) / 0.7);
}

.ai-tool-step-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.ai-sendbtn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: hsl(var(--primary));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: hsl(var(--primary-foreground));
    transition: background .1s;
    flex-shrink: 0;
}

.ai-sendbtn:hover { background: hsl(var(--primary) / 0.85); }
.ai-sendbtn:disabled { opacity: .45; cursor: not-allowed; }

/* Stop-streaming mode: send button morphs into a stop button while a reply is generating */
.ai-sendbtn.is-sending {
    background: hsl(var(--destructive, 0 72% 51%));
    color: hsl(var(--destructive-foreground, 0 0% 100%));
    animation: ai-sendbtn-pulse 1.4s ease-in-out infinite;
}
.ai-sendbtn.is-sending:hover { background: hsl(var(--destructive, 0 72% 51%) / 0.85); }

@keyframes ai-sendbtn-pulse {
    0%, 100% { box-shadow: 0 0 0 0 hsl(var(--destructive, 0 72% 51%) / 0.55); }
    50% { box-shadow: 0 0 0 6px hsl(var(--destructive, 0 72% 51%) / 0); }
}

/* Auto-retry status shown next to typing dots when a stream errored and we're retrying */
.ai-retrying {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: hsl(var(--muted-foreground, 215 16% 47%));
    font-size: 13px;
}
.ai-retrying .ai-retry-status {
    font-style: italic;
    opacity: 0.85;
}

.ai-fnote {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 4px 0 8px;
    gap: 8px;
}
.ai-fnote-scope {
    grid-column: 1;
    justify-self: start;
}
.ai-fnote-brand {
    grid-column: 2;
    font-size: 12px;
    color: hsl(var(--muted-foreground) / 1);
    white-space: nowrap;
    text-align: center;
    pointer-events: none;
}
.ai-ctx-counter {
    grid-column: 3;
    justify-self: end;
    flex-shrink: 0;
    text-align: right;
    font-size: 11px;
    color: hsl(var(--muted-foreground) / 0.9);
    letter-spacing: .02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    transition: opacity .2s;
    cursor: default;
}
.ai-ctx-counter:not(:empty) { cursor: help; }
.ai-ctx-counter:not(:empty) { cursor: help; }

.ai-usage-pill {
    font-size: 11px;
    color: hsl(var(--muted-foreground) / 0.4);
    margin-top: 3px;
    padding: 0 2px;
    letter-spacing: .01em;
    line-height: 1.6;
    user-select: none;
    cursor: help;
}

/* ============================================================
   TYPING INDICATOR
   ============================================================ */
.ai-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
}

.ai-dot {
    width: 6px;
    height: 6px;
    background: hsl(var(--muted-foreground));
    border-radius: 50%;
    animation: ai-pulse .8s infinite;
}

.ai-dot:nth-child(2) { animation-delay: .15s; }
.ai-dot:nth-child(3) { animation-delay: .30s; }

@keyframes ai-pulse {
    0%, 100% { opacity: .3; transform: translateY(0); }
    50%       { opacity: 1; transform: translateY(-2px); }
}

/* ============================================================
   MOBILE  (≤ 640px)
   ============================================================ */

/* Desktop only utility (hidden on mobile) */
.ai-desktop-only { display: flex; }
@media (max-width: 640px) { .ai-desktop-only { display: none !important; } }

/* Hide hamburger in main header on desktop when sidebar is NOT collapsed
   (sidebar already has its own collapse button, no need for duplicate) */
@media (min-width: 641px) {
    #ai-sidebar:not(.ai-sb-collapsed) + #ai-main #ai-hamburger {
        display: none;
    }
}

/* ============================================================
   WINDOWED MODE  (desktop: draggable floating panel)
   ============================================================ */
@media (min-width: 641px) {
    #ai-panel-shell.ai-windowed {
        pointer-events: none;
        background: transparent;
        /* children are positioned via inline styles by JS */
    }

    #ai-panel-shell.ai-windowed #ai-app {
        pointer-events: all;
        position: fixed;   /* JS sets top/left/width/height */
        border-radius: 14px;
        border: 1px solid hsl(var(--border));
        box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
        flex-shrink: 0;
        overflow: visible;  /* allow resize handles to bleed outside */
        min-width: 320px;
        min-height: 380px;
    }

    /* Drag handle — the header */
    #ai-panel-shell.ai-windowed #ai-hdr {
        cursor: grab;
    }
    #ai-panel-shell.ai-windowed #ai-hdr:active {
        cursor: grabbing;
    }
    /* Keep inner header buttons clickable */
    #ai-panel-shell.ai-windowed #ai-hdr button,
    #ai-panel-shell.ai-windowed #ai-hdr input,
    #ai-panel-shell.ai-windowed #ai-hdr a {
        cursor: pointer;
    }

    /* In windowed mode, sidebar is always hidden — no conversation history visible */
    #ai-panel-shell.ai-windowed #ai-sidebar {
        width: 0;
        min-width: 0;
        overflow: hidden;
        border: none;
    }
    #ai-panel-shell.ai-windowed #ai-hamburger {
        display: none;
    }

    /* Resize handles */
    .ai-resize-handle {
        position: absolute;
        z-index: 10;
    }
    /* Edge handles */
    .ai-resize-handle[data-dir="n"]  { top: -4px; left: 8px; right: 8px; height: 8px; cursor: n-resize; }
    .ai-resize-handle[data-dir="s"]  { bottom: -4px; left: 8px; right: 8px; height: 8px; cursor: s-resize; }
    .ai-resize-handle[data-dir="e"]  { right: -4px; top: 8px; bottom: 8px; width: 8px; cursor: e-resize; }
    .ai-resize-handle[data-dir="w"]  { left: -4px; top: 8px; bottom: 8px; width: 8px; cursor: w-resize; }
    /* Corner handles */
    .ai-resize-handle[data-dir="ne"] { top: -4px; right: -4px; width: 14px; height: 14px; cursor: ne-resize; }
    .ai-resize-handle[data-dir="nw"] { top: -4px; left: -4px; width: 14px; height: 14px; cursor: nw-resize; }
    .ai-resize-handle[data-dir="se"] { bottom: -4px; right: -4px; width: 14px; height: 14px; cursor: se-resize; }
    .ai-resize-handle[data-dir="sw"] { bottom: -4px; left: -4px; width: 14px; height: 14px; cursor: sw-resize; }
}

/* Hide resize handles in full-screen mode */
#ai-panel-shell:not(.ai-windowed) .ai-resize-handle {
    display: none;
}

@media (max-width: 640px) {
    /* App is already full-screen; just ensure sidebar overlays content */
    #ai-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100%;
        transform: translateX(-100%);
        z-index: 50;
        width: 260px !important;
        min-width: 260px !important;
        transition: transform .25s ease;
    }

    #ai-sidebar.ai-sb-open {
        transform: translateX(0);
    }

    #ai-sidebar.ai-sb-collapsed {
        transform: translateX(-100%);
    }

    /* Tighter message padding on small screens */
    #ai-message-list {
        padding: 8px 10px 4px;
    }

    /* Prevent breadcrumbs from wrapping and breaking header layout on mobile */
    #ai-scope-breadcrumbs {
        /* Constrain width so header doesn't overflow */
        max-width: calc(100vw - 220px);
    }

    /* Keep header strictly single-line */
    #ai-hdr {
        flex-wrap: nowrap;
    }
}


/* ============================================================
   MARKDOWN RENDERED CONTENT  (.ai-md)
   ============================================================ */
.ai-md {
    color: hsl(var(--foreground));
    font-size: 15px;
    line-height: 1.65;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
    user-select: text !important;
    -webkit-user-select: text !important;
    cursor: text;
}

.ai-md * {
    user-select: text !important;
    -webkit-user-select: text !important;
}

.ai-md .ai-p {
    margin: 0 0 10px;
    color: hsl(var(--foreground));
    line-height: 1.65;
}

.ai-md .ai-p:last-child { margin-bottom: 0; }

/* Remove white-space:pre-wrap so markdown renders correctly */
.a-body.ai-md p,
.a-body.ai-md .ai-p { white-space: normal; }

.ai-md .ai-h1 {
    font-size: 18px;
    font-weight: 700;
    color: hsl(var(--foreground));
    margin: 14px 0 6px;
    line-height: 1.3;
}

.ai-md .ai-h2 {
    font-size: 16px;
    font-weight: 700;
    color: hsl(var(--foreground));
    margin: 12px 0 5px;
    line-height: 1.3;
}

.ai-md .ai-h3 {
    font-size: 14px;
    font-weight: 700;
    color: hsl(var(--muted-foreground));
    margin: 10px 0 4px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.ai-md strong { color: hsl(var(--foreground)); font-weight: 600; }
.ai-md em { color: hsl(var(--muted-foreground)); font-style: italic; }

/* Tables — sleek, GitHub/Notion-inspired with closed (bordered) design */
.ai-md .ai-table-wrap {
    margin: 12px 0;
    overflow-x: auto;
    border: 1px solid hsl(var(--border));
    border-radius: 8px;
    background: hsl(var(--card, var(--background)));
}
.ai-md .ai-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    line-height: 1.5;
}
.ai-md .ai-table thead {
    background: hsl(var(--muted) / 0.5);
}
.ai-md .ai-table th {
    text-align: left;
    font-weight: 600;
    font-size: 12.5px;
    color: hsl(var(--foreground));
    padding: 9px 12px;
    border-bottom: 1px solid hsl(var(--border));
    white-space: nowrap;
}
.ai-md .ai-table td {
    padding: 9px 12px;
    color: hsl(var(--foreground));
    border-bottom: 1px solid hsl(var(--border));
    vertical-align: top;
}
.ai-md .ai-table tbody tr:last-child td {
    border-bottom: none;
}
.ai-md .ai-table tbody tr:hover {
    background: hsl(var(--muted) / 0.35);
}
.ai-md .ai-table th + th,
.ai-md .ai-table td + td {
    border-left: 1px solid hsl(var(--border));
}
.ai-md .ai-table code {
    font-size: 12.5px;
}

.ai-md .ai-hr {
    border: none;
    border-top: 1px solid hsl(var(--border));
    margin: 12px 0;
}

.ai-md .ai-bq {
    border-left: 3px solid hsl(var(--border));
    padding: 6px 12px;
    margin: 8px 0;
    color: hsl(var(--muted-foreground));
    font-style: italic;
    background: hsl(var(--secondary) / 0.5);
    border-radius: 0 6px 6px 0;
}

.ai-md .ai-ul {
    margin: 6px 0 10px 18px;
    padding: 0;
    list-style: disc;
    color: hsl(var(--foreground));
}

.ai-md .ai-ul li {
    margin-bottom: 4px;
    line-height: 1.55;
}

/* Inline code */
.ai-inline-code {
    background: hsl(var(--secondary));
    color: hsl(38 92% 50%);
    padding: 2px 6px;
    border-radius: 5px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    border: 1px solid hsl(var(--border));
}

/* ---- Code block ---- */
.ai-cb {
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 10px;
    overflow: hidden;
    margin: 8px 0 10px;
}

.ai-cb-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    background: hsl(var(--secondary));
    border-bottom: 1px solid hsl(var(--border));
}

.ai-cb-lang {
    font-size: 12px;
    font-weight: 600;
    color: hsl(var(--muted-foreground));
    letter-spacing: .04em;
    text-transform: lowercase;
    font-family: 'Courier New', monospace;
}

.ai-cb-copy {
    background: transparent;
    border: 1px solid hsl(var(--border));
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: color .1s, background .1s;
    font-family: inherit;
}

.ai-cb-copy:hover { color: hsl(var(--foreground)); background: hsl(var(--accent)); }

.ai-cb-pre {
    margin: 0;
    padding: 14px 16px;
    overflow-x: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    line-height: 1.6;
    color: hsl(var(--foreground));
    background: transparent;
    white-space: pre;
    tab-size: 2;
}

.ai-cb-pre code {
    background: transparent;
    border: none;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

/* ---- HTML preview block ---- */
.ai-html-preview-wrap {
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 10px;
    overflow: hidden;
    margin: 8px 0 10px;
}

.ai-html-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    background: hsl(var(--secondary));
    border-bottom: 1px solid hsl(var(--border));
}

.ai-preview-toggle {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: opacity .15s;
}
.ai-preview-toggle:hover { opacity: .85; }

.ai-preview-frame {
    display: block;
    width: 100%;
    min-height: 340px;
    border: none;
    background: #fff;
}
.ai-preview-frame.ai-hidden { display: none !important; }

/* Fullscreen preview button */
.ai-preview-fullscreen {
    background: transparent;
    border: 1px solid hsl(var(--border));
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: color .1s, background .1s;
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: inherit;
}
.ai-preview-fullscreen:hover { color: hsl(var(--foreground)); background: hsl(var(--accent)); }

/* Fullscreen overlay */
.ai-preview-fs-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    background: hsl(var(--background));
}
.ai-preview-fs-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid hsl(var(--border));
    font-size: 13px;
    font-weight: 600;
    color: hsl(var(--foreground));
    flex-shrink: 0;
    font-family: 'Inter', sans-serif;
}
.ai-preview-fs-close {
    background: transparent;
    border: 1px solid hsl(var(--border));
    border-radius: var(--border);
    padding: 5px 14px;
    font-size: 13px;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    font-family: inherit;
    transition: background .1s, color .1s;
}
.ai-preview-fs-close:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.ai-preview-fs-iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: #fff;
    display: block;
}

.ai-html-src-details {
    border-top: 1px solid hsl(var(--border));
}
.ai-html-src-details summary {
    padding: 7px 14px;
    font-size: 12px;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    user-select: none;
    background: hsl(var(--secondary));
}
.ai-html-src-details[open] summary { border-bottom: 1px solid hsl(var(--border)); }
.ai-html-src-details .ai-cb-pre { border-radius: 0; }

/* ---- KaTeX math ---- */
.ai-math-block {
    overflow-x: auto;
    padding: 8px 0;
    text-align: center;
}
.ai-math-block .katex-display { margin: 0; }

.ai-math-inline .katex { font-size: 1em; }

/* ============================================================
   DESIGN STYLE OVERRIDES (soft / sharp / brutalist / rounded)
   ----
   The site applies data-style="soft|sharp|brutalist|rounded" on
   <html>. Its global rule only re-radiuses Tailwind classes
   ([class*="rounded-"]), so the assistant — which uses custom
   classes with hardcoded border-radius values — never reflects
   the chosen style. These rules wire the widget into the system.
   True circular elements (avatar, FAB, mic/send, X buttons,
   spinners, typing dots) keep their 50% radius unconditionally.
   ============================================================ */

/* ---- SHARP & BRUTALIST: flatten every corner inside the widget ---- */
html[data-style="sharp"] #ai-assistant-root *,
html[data-style="brutalist"] #ai-assistant-root *,
html[data-style="sharp"] #ai-img-lightbox img,
html[data-style="brutalist"] #ai-img-lightbox img {
    border-radius: 0 !important;
}

/* Re-assert true circles (avatars, FAB, icon buttons, dots, spinners) */
html[data-style="sharp"] #ai-assistant-root #ai-launcher,
html[data-style="brutalist"] #ai-assistant-root #ai-launcher,
html[data-style="sharp"] #ai-assistant-root .a-logo,
html[data-style="brutalist"] #ai-assistant-root .a-logo,
html[data-style="sharp"] #ai-assistant-root .ai-sendbtn,
html[data-style="brutalist"] #ai-assistant-root .ai-sendbtn,
html[data-style="sharp"] #ai-assistant-root .ai-micbtn,
html[data-style="brutalist"] #ai-assistant-root .ai-micbtn,
html[data-style="sharp"] #ai-assistant-root .ai-attach-remove,
html[data-style="brutalist"] #ai-assistant-root .ai-attach-remove,
html[data-style="sharp"] #ai-assistant-root .ai-attach-spinner,
html[data-style="brutalist"] #ai-assistant-root .ai-attach-spinner,
html[data-style="sharp"] #ai-assistant-root .ai-dot,
html[data-style="brutalist"] #ai-assistant-root .ai-dot,
html[data-style="sharp"] #ai-assistant-root .ai-tool-step-icon::before,
html[data-style="brutalist"] #ai-assistant-root .ai-tool-step-icon::before,
html[data-style="sharp"] #ai-img-lightbox-close,
html[data-style="brutalist"] #ai-img-lightbox-close {
    border-radius: 50% !important;
}

/* ---- SOFT: bump the radii on container surfaces inside the widget ---- */
html[data-style="soft"] #ai-assistant-root .ai-iwrap,
html[data-style="soft"] #ai-assistant-root .ai-share-dialog,
html[data-style="soft"] #ai-assistant-root .ai-settings-panel,
html[data-style="soft"] #ai-assistant-root .ai-ctx,
html[data-style="soft"] #ai-assistant-root #ai-model-menu {
    border-radius: 1.25rem;
}

html[data-style="soft"] #ai-assistant-root .u-bub {
    border-radius: 1.5rem;
}

html[data-style="soft"] #ai-assistant-root .ai-cb,
html[data-style="soft"] #ai-assistant-root .ai-html-preview-wrap,
html[data-style="soft"] #ai-assistant-root .ai-error-row,
html[data-style="soft"] #ai-assistant-root .ai-toast,
html[data-style="soft"] #ai-assistant-root .ai-active-filter,
html[data-style="soft"] #ai-assistant-root .ai-attach-item.is-file,
html[data-style="soft"] #ai-assistant-root .u-bub-thumb,
html[data-style="soft"] #ai-assistant-root .ai-attach-item.is-image,
html[data-style="soft"] #ai-assistant-root .ai-attach-thumb,
html[data-style="soft"] #ai-img-lightbox img {
    border-radius: 1rem;
}

html[data-style="soft"] #ai-assistant-root .ai-sb-search-wrap,
html[data-style="soft"] #ai-assistant-root .ai-sb-toggle-row,
html[data-style="soft"] #ai-assistant-root .ai-sb-nav,
html[data-style="soft"] #ai-assistant-root .ai-model-btn,
html[data-style="soft"] #ai-assistant-root .ai-model-opt,
html[data-style="soft"] #ai-assistant-root .ai-ci,
html[data-style="soft"] #ai-assistant-root .ai-sdlg-public,
html[data-style="soft"] #ai-assistant-root .ai-sdlg-private,
html[data-style="soft"] #ai-assistant-root .ai-sdlg-url-input,
html[data-style="soft"] #ai-assistant-root .ai-sdlg-copy-btn,
html[data-style="soft"] #ai-assistant-root .ai-sdlg-toggle-btn,
html[data-style="soft"] #ai-assistant-root .ai-settings-del-all-btn,
html[data-style="soft"] #ai-assistant-root .ai-primary-btn {
    border-radius: 0.875rem;
}

html[data-style="soft"] #ai-assistant-root .ai-ib,
html[data-style="soft"] #ai-assistant-root .ai-msg-action,
html[data-style="soft"] #ai-assistant-root .ai-cb-copy,
html[data-style="soft"] #ai-assistant-root .ai-preview-toggle,
html[data-style="soft"] #ai-assistant-root .ai-preview-fullscreen,
html[data-style="soft"] #ai-assistant-root .ai-preview-fs-close,
html[data-style="soft"] #ai-assistant-root .ai-retry-btn,
html[data-style="soft"] #ai-assistant-root .ai-inline-code,
html[data-style="soft"] #ai-assistant-root .ai-history-rename-input {
    border-radius: 0.625rem;
}

