﻿/* -------------------------------------------------------
   AI BRAIN v5 � Premium Chat Experience
   Centered column � Clean typography � Refined details
   Uses design tokens from /static/css/common.css
   ------------------------------------------------------- */

/* -----------------------------------------------------
   �1  LAYOUT SHELL
   ----------------------------------------------------- */
.ai-brain-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.brain-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* -----------------------------------------------------
   �2  BRAIN SUB-HEADER � Compact toolbar
   ----------------------------------------------------- */
.brain-subheader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--color-surface-alpha-92);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    gap: 16px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.brain-subheader__left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.brain-subheader__eyebrow {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-primary);
}

.brain-subheader__title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin: 0;
}

.brain-subheader__subtitle {
    font-size: 0.82rem;
    color: var(--color-text-sec);
    margin: 0;
    line-height: 1.4;
}

.brain-subheader__center {
    display: flex;
    align-items: center;
}

.brain-subheader__right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Chat/Studio switcher shown inside subheader only on mobile
   (topbar version is hidden via common.css ≤768px) */
.brain-subheader__mode-switcher {
    display: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
}

.brain-subheader__action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    border-radius: 10px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.brain-subheader__action-btn svg { width: 14px; height: 14px; }

.brain-subheader__action-btn:hover {
    background: var(--color-page-bg);
    color: var(--color-text);
}

.brain-subheader__action-btn--new {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-text-inv);
    box-shadow: 0 1px 3px var(--color-primary-alpha-10);
}

.brain-subheader__action-btn--new:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
    color: var(--color-text-inv);
    box-shadow: 0 2px 8px rgba(0,82,255,0.4);
}

.brain-subheader__action-btn--delete {
    color: var(--color-error);
    border-color: var(--color-danger-alpha-20);
}

.brain-subheader__action-btn--delete:hover {
    background: var(--color-danger-alpha-05);
    border-color: var(--color-danger-alpha-12);
}

/* -----------------------------------------------------
   �3  CONTENT AREA
   ----------------------------------------------------- */
.brain-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* -----------------------------------------------------
   �4  RECENT CHATS PANEL � Dark sidebar
   ----------------------------------------------------- */
.recent-chats {
    width: 280px;
    flex-shrink: 0;
    background: var(--color-surface-alpha-92);
    border-right: 1px solid rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    overflow: visible;
    position: relative;
    transition: width 0.25s ease, min-width 0.25s ease, border-color 0.2s ease, background 0.2s ease;
}

.recent-chats.collapsed {
    width: 0;
    min-width: 0;
    background: transparent;
    border-right-color: transparent;
}

.recent-chats.collapsed .recent-chats__list {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.recent-chats.collapsed .recent-chats__header {
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    padding: 0;
    border-bottom: none;
    overflow: visible;
}

.recent-chats.collapsed .recent-chats__heading,
.recent-chats.collapsed .recent-chats__new-btn {
    display: none;
}

.recent-chats.collapsed .recent-chats__actions {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    overflow: visible;
}

.recent-chats__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--color-border-lt);
    flex-shrink: 0;
    overflow: hidden;
    transition: opacity 0.16s ease, visibility 0.16s ease;
}

.recent-chats__title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-sec);
}

.recent-chats__heading {
    display: flex;
    align-items: center;
    min-width: 0;
}

.recent-chats__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
}

.recent-chats__new-btn {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    border: 1px solid var(--color-border);
    background: var(--color-page-bg);
    color: var(--color-text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.recent-chats__new-btn span {
    font-size: 1.1rem;
    line-height: 1;
}

.recent-chats__new-btn:hover {
    background: var(--color-border-lt);
    color: var(--color-text-sec);
}

.recent-chats__toggle {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    border: 1px solid var(--color-border);
    background: var(--color-page-bg);
    color: var(--color-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 5;
}

.recent-chats__toggle svg { width: 14px; height: 14px; }

.recent-chats__toggle:hover {
    background: var(--color-border-lt);
    color: var(--color-text-sec);
}

.recent-chats__list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 8px 16px;
    transition: opacity 0.16s ease, visibility 0.16s ease;
}

.recent-chats.collapsed .recent-chats__toggle {
    position: absolute;
    top: 18px;
    left: 20px;
    transform: translateX(-50%) rotate(180deg);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    background: var(--color-surface);
    border-color: var(--color-border);
    box-shadow: var(--shadow-md);
}

.recent-chats__list::-webkit-scrollbar { width: 2px; }
.recent-chats__list::-webkit-scrollbar-track { background: transparent; }
.recent-chats__list::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }

.recent-chats__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 16px;
    text-align: center;
}

.recent-chats__empty svg { width: 32px; height: 32px; color: var(--color-border); }
.recent-chats__empty span { font-size: 0.76rem; color: var(--color-text-sec); }

.recent-chats__date-label {
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-sec);
    padding: 14px 10px 6px;
}

.recent-chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    transition: all 0.15s ease;
    margin-bottom: 2px;
    border: 1px solid transparent;
}

.recent-chat-item:hover {
    background: var(--color-page-bg);
}

.recent-chat-item__icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--color-primary-alpha-10) 0%, var(--color-blue-alpha-08) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--color-primary);
}

.recent-chat-item__info { flex: 1; min-width: 0; }

.recent-chat-item__actions {
    position: relative;
    flex-shrink: 0;
}

.recent-chat-item__menu-btn {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
    opacity: 0;
    transition: all 0.15s ease;
}

.recent-chat-item:hover .recent-chat-item__menu-btn,
.recent-chat-item__menu-btn:focus,
.recent-chat-item__actions.is-open .recent-chat-item__menu-btn {
    opacity: 1;
}

.recent-chat-item__menu-btn:hover,
.recent-chat-item__menu-btn:focus {
    background: var(--color-page-bg);
    border-color: var(--color-border);
    color: var(--color-text-sec);
}

.recent-chat-item__menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 116px;
    padding: 5px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    display: none;
    z-index: 20;
}

.recent-chat-item__menu.is-open {
    display: flex;
    flex-direction: column;
}

.recent-chat-item__menu button {
    width: 100%;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--color-text);
    cursor: pointer;
    font-size: 0.76rem;
    line-height: 1.2;
    padding: 7px 8px;
    text-align: left;
}

.recent-chat-item__menu button:hover,
.recent-chat-item__menu button:focus {
    background: var(--color-page-bg);
    color: var(--color-text);
}

.recent-chat-item__text {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.recent-chat-item__time {
    font-size: 0.65rem;
    color: var(--color-text-sec);
    margin-top: 2px;
}

.recent-chat-item--active {
    background: linear-gradient(135deg, var(--color-primary-alpha-08) 0%, var(--color-blue-alpha-08) 100%);
    border-color: var(--color-primary-alpha-12);
}

.recent-chat-item--active .recent-chat-item__icon {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 1px 4px var(--color-primary-alpha-10);
}

.recent-chat-item--active .recent-chat-item__text {
    color: var(--color-text);
    font-weight: 600;
}

/* -----------------------------------------------------
   �5  MODE SWITCHING
   ----------------------------------------------------- */
.brain-content.mode-chat .chat-panel { flex: 1; }
.brain-content.mode-studio .chat-panel { flex: 1; }

/* -----------------------------------------------------
   CHAT PANEL
   ----------------------------------------------------- */
.chat-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    background:
        radial-gradient(circle at 10% 0%, var(--color-primary-alpha-06) 0%, transparent 36%),
        radial-gradient(circle at 90% 10%, rgba(82,52,16,0.04) 0%, rgba(82,52,16,0) 34%),
        var(--gradient-warm-bg);
}

/* -----------------------------------------------------
   �8  WELCOME SCREEN
   ----------------------------------------------------- */
.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 48px 32px;
    position: relative;
    overflow: hidden;
}

.chat-welcome::before {
    content: '';
    position: absolute;
    width: 560px;
    height: 560px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--color-primary-alpha-06) 0%, rgba(139,92,246,0.03) 30%, transparent 60%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -55%);
    pointer-events: none;
}

.chat-welcome__hero {
    position: relative;
    margin-bottom: 28px;
}

.chat-welcome__brain {
    width: 72px;
    height: 72px;
    border-radius: 12px;
    background: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px var(--color-primary-alpha-12);
    animation: heroFloat 6s ease-in-out infinite;
    position: relative;
    z-index: 1;
}

.chat-welcome__brain svg {
    width: 42px;
    height: 42px;
}

@keyframes heroFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.chat-welcome__orb {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}

.chat-welcome__orb:nth-child(1) {
    width: 8px;
    height: 8px;
    background: var(--color-primary);
    box-shadow: 0 0 10px rgba(0,82,255,0.5);
    top: -6px;
    left: 50%;
    animation: orbit 8s linear infinite;
}

.chat-welcome__orb:nth-child(2) {
    width: 6px;
    height: 6px;
    background: var(--color-purple-500);
    box-shadow: 0 0 8px rgba(168,85,247,0.5);
    bottom: -4px;
    right: 10%;
    animation: orbit 11s linear infinite reverse;
}

.chat-welcome__orb:nth-child(3) {
    width: 5px;
    height: 5px;
    background: var(--color-accent);
    box-shadow: 0 0 8px rgba(0,211,149,0.5);
    top: 40%;
    left: -10px;
    animation: orbit 14s linear infinite;
}

@keyframes orbit {
    from { transform: rotate(0deg) translateX(44px) rotate(0deg); }
    to { transform: rotate(360deg) translateX(44px) rotate(-360deg); }
}

.chat-welcome__title {
    font-size: 1.55rem;
    font-weight: 500;
    color: var(--color-text);
    letter-spacing: -0.03em;
    margin-bottom: 8px;
    line-height: 1.2;
}

.chat-welcome__title-highlight {
    background: var(--color-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.chat-welcome__desc {
    font-size: 0.9rem;
    color: var(--color-text);
    max-width: 460px;
    line-height: 1.7;
    margin-bottom: 32px;
}

.chat-welcome__suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    max-width: 520px;
    width: 100%;
}

.chat-welcome__suggestion {
    background: var(--color-surface-alpha-92);
    border: 1px solid rgba(0,0,0,0.06);
    color: var(--color-text);
    padding: 14px 16px;
    border-radius: var(--radius-xl);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.25s ease;
    font-family: inherit;
    font-weight: 500;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    line-height: 1.4;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);
}

.chat-welcome__suggestion:hover {
    border-color: rgba(0,0,0,0.1);
    color: var(--color-text);
    background: var(--color-surface-alpha-96);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.05);
    transform: translateY(-2px);
}

.chat-welcome__suggestion-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-welcome__suggestion-icon svg {
    width: 16px;
    height: 16px;
    stroke-width: 1.5;
    color: inherit;
}

.chat-welcome__suggestion:nth-child(1) .chat-welcome__suggestion-icon { background: linear-gradient(135deg, var(--color-primary-alpha-12) 0%, var(--color-blue-alpha-08) 100%); color: var(--color-primary); }
.chat-welcome__suggestion:nth-child(2) .chat-welcome__suggestion-icon { background: linear-gradient(135deg, var(--color-success-alpha-10) 0%, var(--color-success-alpha-08) 100%); color: var(--color-success); }
.chat-welcome__suggestion:nth-child(3) .chat-welcome__suggestion-icon { background: linear-gradient(135deg, var(--color-amber-alpha-12) 0%, var(--color-amber-alpha-08) 100%); color: var(--color-amber); }
.chat-welcome__suggestion:nth-child(4) .chat-welcome__suggestion-icon { background: linear-gradient(135deg, var(--color-role-admin-bg) 0%, var(--color-purple-alpha-08) 100%); color: var(--color-purple-500); }

.chat-welcome__suggestion-text { flex: 1; min-width: 0; }

/* -----------------------------------------------------
   �9  CHAT MESSAGES � Centered column layout
   ----------------------------------------------------- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.08); border-radius: 4px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.14); }

/* Each message is centered in a 780px column */
.chat-msg {
    width: 100%;
    max-width: 780px;
    padding: 8px 32px;
    display: flex;
    animation: msgSlideIn 0.3s ease;
}

@keyframes msgSlideIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* -- User message � right-aligned indigo bubble -- */
.chat-msg--user {
    justify-content: flex-end;
}

.chat-msg--user .chat-msg__content {
    max-width: 68%;
    background: var(--color-primary);
    color: var(--color-text-inv);
    padding: 12px 18px;
    border-radius: 12px 18px 4px 18px;
    font-size: 0.86rem;
    line-height: 1.65;
    word-break: break-word;
    box-shadow: 0 1px 3px var(--color-primary-alpha-12);
}

/* -- Assistant message � clean text block with avatar -- */
.chat-msg--assistant {
    justify-content: flex-start;
}

.chat-msg--assistant .chat-msg__content {
    width: 100%;
    background: transparent;
    padding: 4px 0;
    font-size: 0.86rem;
    line-height: 1.75;
    color: var(--color-text);
    word-break: break-word;
}

.chat-msg--assistant .chat-msg__content-inner {
    position: relative;
    margin-left: 44px;
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
}

/* AI avatar � single, solid pseudo-element (no ::after) */
.chat-msg--assistant .chat-msg__content-inner::before {
    content: '';
    position: absolute;
    left: -44px;
    top: 2px;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: var(--color-primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3l1.5 4.5L18 9l-4.5 1.5L12 15l-1.5-4.5L6 9l4.5-1.5L12 3z'/%3E%3Cpath d='M18 14l.8 2.2L21 17l-2.2.8L18 20l-.8-2.2L15 17l2.2-.8L18 14z'/%3E%3C/svg%3E") no-repeat center / 18px 18px;
    box-shadow: 0 2px 6px var(--color-primary-alpha-10);
}

/* Hide the JS-generated avatar div (unused) */
.chat-msg__avatar { display: none; }

/* -- Message typography -- */
.chat-msg__content p { margin-bottom: 10px; line-height: 1.75; }
.chat-msg__content p:last-child { margin-bottom: 0; }
.chat-msg__content strong { font-weight: 500; }
.chat-msg--assistant .chat-msg__content strong { color: var(--color-text); }

/* Headings inside AI responses */
.chat-msg__content h1,
.chat-msg__content h2,
.chat-msg__content h3 {
    font-weight: 500;
    color: var(--color-text);
    line-height: 1.3;
    margin: 18px 0 6px;
}
.chat-msg__content h1 { font-size: 1rem; }
.chat-msg__content h2 { font-size: 0.94rem; letter-spacing: -0.01em; }
.chat-msg__content h3 {
    font-size: 0.86rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-primary);
}
.chat-msg__content h1:first-child,
.chat-msg__content h2:first-child,
.chat-msg__content h3:first-child { margin-top: 4px; }

/* Blockquotes � document quotes / source excerpts */
.chat-msg__content blockquote {
    border-left: 3px solid var(--color-primary);
    background: var(--color-primary-alpha-05);
    margin: 12px 0;
    padding: 8px 14px;
    border-radius: 0 8px 8px 0;
    color: var(--color-text-sec);
    font-style: italic;
    font-size: 0.84rem;
}
.chat-msg__content blockquote p { margin-bottom: 4px; }
.chat-msg__content blockquote p:last-child { margin-bottom: 0; }

/* Horizontal rule � section separator */
.chat-msg__content hr {
    border: none;
    border-top: 1px solid var(--color-border-lt);
    margin: 14px 0;
}

/* Lists */
.chat-msg__content ul { padding-left: 20px; margin: 8px 0; list-style-type: disc; }
.chat-msg__content ol { padding-left: 20px; margin: 8px 0; list-style-type: decimal; }
.chat-msg__content li { margin-bottom: 5px; line-height: 1.65; }
.chat-msg__content li:last-child { margin-bottom: 0; }

.chat-msg__content code {
    background: var(--color-primary-alpha-06);
    padding: 1px 6px;
    border-radius: 5px;
    font-family: var(--font-mono);
    font-size: 0.82em;
    color: var(--color-primary-dark);
}

.chat-msg--user .chat-msg__content code {
    background: var(--color-surface-alpha-18);
    color: var(--color-text-inv);
}

.chat-msg__content pre {
    background: var(--color-dark-700);
    border-radius: 12px;
    padding: 16px;
    overflow-x: auto;
    margin: 10px 0;
}

.chat-msg__content pre code {
    background: none;
    padding: 0;
    color: var(--color-purple-light-bg);
    font-size: 0.8rem;
}

/* -----------------------------------------------------
   �10  SOURCES
   ----------------------------------------------------- */
.chat-msg__sources {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid rgba(0,0,0,0.06);
}

/* remove default <details> marker */
.chat-msg__sources summary { list-style: none; }
.chat-msg__sources summary::-webkit-details-marker { display: none; }

.chat-msg__sources-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    padding: 2px 0;
}

.chat-msg__sources-title {
    font-size: 0.66rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-sec);
}

.chat-msg__sources-count {
    font-size: 0.6rem;
    font-weight: 700;
    background: rgba(0,0,0,0.07);
    color: var(--color-text-sec);
    border-radius: 20px;
    padding: 1px 6px;
}

.chat-msg__sources-chevron {
    width: 10px;
    height: 10px;
    color: var(--color-text-sec);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.chat-msg__sources[open] .chat-msg__sources-chevron {
    transform: rotate(180deg);
}

.chat-msg__source-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    animation: sourcesReveal 0.2s ease;
}

@keyframes sourcesReveal {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-msg__source {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: rgba(0,0,0,0.03);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-primary);
    cursor: default;
    transition: all 0.2s ease;
}

.chat-msg__source:hover {
    border-color: rgba(0,0,0,0.12);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.chat-msg__source-icon { font-size: 0.65rem; }

/* -----------------------------------------------------
   �11  TYPING INDICATOR
   ----------------------------------------------------- */
.chat-typing {
    width: 100%;
    max-width: 780px;
    padding: 8px 32px;
    animation: msgSlideIn 0.3s ease;
}

.chat-typing__bubble {
    position: relative;
    padding-left: 44px;
}

/* Avatar on typing � matches assistant avatar */
.chat-typing__bubble::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: var(--color-primary);
    box-shadow: 0 2px 6px var(--color-primary-alpha-10);
    animation: avatarPulse 2s ease-in-out infinite;
}

@keyframes avatarPulse {
    0%, 100% { box-shadow: 0 2px 6px var(--color-primary-alpha-10); }
    50% { box-shadow: 0 2px 16px rgba(0,82,255,0.45); }
}

.chat-typing__inner {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 30px;
}

.chat-typing__label {
    font-size: 0.76rem;
    color: var(--color-text-sec);
    font-style: italic;
}

/* -----------------------------------------------------
   �12  LIVE DATA CARDS
   ----------------------------------------------------- */
.live-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 12px 0;
}

.live-card {
    background: var(--color-surface-alpha-92);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: var(--radius-xl);
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.25s ease, transform 0.25s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);
}

.live-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
}

.live-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.05);
    transform: translateY(-1px);
}

.live-card--timeline::before { background: var(--color-primary); }
.live-card--calendar::before { background: var(--color-accent); }
.live-card--workspace::before { background: var(--color-warning); }

.live-card__header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding-left: 10px;
}

.live-card__icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.live-card--timeline .live-card__icon { background: var(--color-primary-alpha-08); }
.live-card--calendar .live-card__icon { background: var(--color-success-alpha-08); }
.live-card--workspace .live-card__icon { background: var(--color-amber-alpha-08); }

.live-card__title {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--color-text);
}

.live-card__badge {
    font-size: 0.62rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: var(--radius-full);
    background: var(--color-primary-alpha-06);
    color: var(--color-primary);
    margin-left: auto;
    font-family: var(--font-mono);
}

.live-card__body { padding-left: 10px; }

.live-card__item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 0;
    font-size: 0.78rem;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border-lt);
}

.live-card__item:last-child { border-bottom: none; }

.live-card__item-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
}

.live-card--timeline .live-card__item-dot { background: var(--color-primary); }
.live-card--calendar .live-card__item-dot { background: var(--color-accent); }
.live-card--workspace .live-card__item-dot { background: var(--color-warning); }

.live-card__item-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.live-card__item-meta {
    font-size: 0.68rem;
    color: var(--color-text-sec);
    white-space: nowrap;
    font-family: var(--font-mono);
}

/* -----------------------------------------------------
   �13  CHAT INPUT AREA
   ----------------------------------------------------- */
.chat-input-area {
    flex-shrink: 0;
    padding: 0 32px calc(20px + env(safe-area-inset-bottom, 0px));
    position: relative;
}

.chat-input-area::before {
    content: '';
    position: absolute;
    top: -32px;
    left: 0;
    right: 0;
    height: 32px;
    background: linear-gradient(to top, var(--color-warm-100), transparent);
    pointer-events: none;
}

.chat-composer-shell {
    max-width: 780px;
    margin: 10px auto 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-composer-status {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: transparent;
    color: var(--color-text-sec);
    font-size: 0.72rem;
    font-weight: 600;
    min-width: 220px;
}

.chat-composer-status[data-state="busy"] {
    background: var(--color-amber-alpha-10);
    color: var(--color-warning-dark);
}

.chat-composer-status[data-state="success"] {
    background: var(--color-success-alpha-10);
    color: var(--color-success-darker);
}

.chat-composer-status[data-state="error"] {
    background: var(--color-danger-alpha-10);
    color: var(--color-error-dark);
}

/* Upload progress bar inside composer */
.chat-upload-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 0;
}

.chat-upload-progress__track {
    flex: 1;
    height: 5px;
    border-radius: 3px;
    background: var(--color-border, rgba(0,0,0,0.1));
    overflow: hidden;
}

.chat-upload-progress__bar {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-secondary, var(--color-primary)));
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-upload-progress__bar--error {
    background: var(--color-error) !important;
    transition: width 0.2s ease;
}

.chat-upload-progress__label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-text-sec);
    white-space: nowrap;
    min-width: 74px;
    text-align: right;
}

.chat-attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    padding: 8px 12px;
    border-radius: 14px;
    background: var(--color-surface-alpha-92);
    border: 1px solid rgba(0,0,0,0.06);
    color: var(--color-text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.chat-attachment-chip--pending,
.chat-attachment-chip--processing {
    border-color: var(--color-amber-alpha-18);
    background: rgba(255,251,235,0.96);
}

.chat-attachment-chip--ready {
    border-color: var(--color-success-alpha-18);
    background: rgba(236,253,245,0.96);
}

.chat-attachment-chip--error {
    border-color: var(--color-danger-alpha-15);
    background: rgba(254,242,242,0.96);
}

.chat-attachment-chip__icon {
    font-size: 0.82rem;
    flex-shrink: 0;
}

.chat-attachment-chip__name {
    font-size: 0.74rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 240px;
}

.chat-attachment-chip__meta {
    font-size: 0.68rem;
    color: var(--color-text-sec);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chat-file-input {
    display: none;
}

.chat-input-wrapper {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--color-surface-alpha-96);
    border: 1px solid rgba(17,24,39,0.10);
    border-radius: 999px;
    padding: 10px 10px 10px 12px;
    transition: all 0.25s ease;
    box-shadow: 0 10px 30px rgba(15,23,42,0.06), 0 2px 8px rgba(15,23,42,0.04);
}

.chat-input-wrapper:focus-within {
    border-color: var(--color-primary-alpha-12);
    box-shadow:
        0 0 0 3px var(--color-primary-alpha-08),
        0 14px 34px rgba(15,23,42,0.08);
}

.chat-upload-menu-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.chat-attach-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--color-neutral-900);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, transform 0.2s ease;
}

.chat-attach-btn svg,
.chat-voice-btn svg,
.chat-send-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chat-attach-btn:hover {
    background: rgba(15,23,42,0.05);
    transform: scale(1.03);
}

.chat-upload-menu {
    position: absolute;
    left: 0;
    bottom: calc(100% + 12px);
    width: min(250px, calc(100vw - 32px));
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: 14px;
    background: var(--color-surface-alpha-96);
    box-shadow: 0 18px 46px rgba(15,23,42,0.16), 0 4px 14px rgba(15,23,42,0.08);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(8px) scale(0.98);
    transform-origin: bottom left;
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
    z-index: 40;
}

.chat-upload-menu.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.chat-upload-menu__title {
    padding: 6px 8px 10px;
    font-size: 0.76rem;
    font-weight: 800;
    color: var(--color-text-sec);
    letter-spacing: 0.01em;
}

.chat-upload-menu__option {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 8px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--color-text);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: background 0.16s ease, transform 0.16s ease;
}

.chat-upload-menu__option:hover {
    background: var(--color-neutral-100);
    transform: translateX(2px);
}

.chat-upload-menu__icon {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-upload-menu__icon svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chat-upload-menu__icon--image {
    background: rgba(34,197,94,0.12);
    color: #15803d;
}

.chat-upload-menu__icon--pdf {
    background: rgba(239,68,68,0.12);
    color: #dc2626;
}

.chat-upload-menu__icon--recording {
    background: rgba(99,102,241,0.12);
    color: #4f46e5;
}

.chat-upload-menu__icon--document {
    background: rgba(14,165,233,0.12);
    color: #0284c7;
}

.chat-upload-menu__label {
    font-size: 0.88rem;
    font-weight: 750;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.94rem;
    font-family: inherit;
    color: var(--color-text);
    resize: none;
    max-height: 140px;
    min-height: 24px;
    line-height: 1.45;
    padding: 9px 0;
    outline: none;
}

.chat-input::placeholder {
    color: var(--color-neutral-400);
}

.chat-voice-btn {
    height: 46px;
    padding: 0 18px 0 12px;
    border-radius: 999px;
    border: none;
    background: var(--color-neutral-100);
    color: var(--color-neutral-900);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    transition: all 0.2s ease;
}

.chat-voice-btn:hover {
    background: var(--color-neutral-200);
}

.chat-voice-btn__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--color-neutral-900);
}

.chat-voice-btn.is-listening {
    background: var(--color-danger-alpha-12);
    color: var(--color-error-dark);
    box-shadow: 0 0 0 4px var(--color-danger-alpha-10);
}

.chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--color-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px var(--color-primary-alpha-10);
}

.chat-send-btn:hover {
    background: var(--color-primary-dark);
    box-shadow: 0 2px 6px var(--color-primary-alpha-12);
}

.chat-send-btn:active { transform: scale(0.95); }

.chat-send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

.voice-visualizer-container {
    width: 120px;
    min-width: 120px;
    max-width: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 46px;
    overflow: hidden;
    flex-shrink: 0;
}

.voice-visualizer-container.hidden {
    display: none;
}

.voice-visualizer {
    width: 120px;
    height: 40px;
    display: block;
    image-rendering: pixelated;
}

/* -----------------------------------------------------
   �14  QUICK PROMPTS
   ----------------------------------------------------- */
.chat-quick-prompts {
    max-width: 780px;
    margin: 0 auto 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}

.chat-quick-prompt {
    background: var(--color-surface-alpha-92);
    border: 1px solid rgba(0,0,0,0.06);
    color: var(--color-text);
    padding: 7px 14px;
    border-radius: var(--radius-xl);
    font-size: 0.74rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    font-family: inherit;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.chat-quick-prompt:hover {
    border-color: rgba(0,0,0,0.12);
    color: var(--color-primary);
    background: var(--color-surface-alpha-96);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* -----------------------------------------------------
   �15  DELETE MODAL
   ----------------------------------------------------- */
.modal-overlay {
    z-index: 9999;
}

.modal-box {
    padding: 28px;
    max-width: 400px;
    text-align: center;
}

.modal-box__icon { font-size: 2.4rem; margin-bottom: 12px; }

.modal-box__title {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 6px;
    letter-spacing: -0.02em;
}

.modal-box__desc {
    font-size: 0.82rem;
    color: var(--color-text-sec);
    line-height: 1.6;
    margin-bottom: 20px;
}

.modal-box__actions { display: flex; gap: 8px; justify-content: center; }

/* -----------------------------------------------------
   �16  RESPONSIVE
   ----------------------------------------------------- */
@media (max-width: 1024px) {
    .recent-chats {
        width: 0;
        min-width: 0;
        background: transparent;
        border-right-color: transparent;
    }
    .recent-chats .recent-chats__header,
    .recent-chats .recent-chats__list {
        display: none;
    }
}

@media (max-width: 768px) {
    /* Two-row subheader on mobile: title row + actions row */
    .brain-subheader {
        padding: 10px 16px;
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .brain-subheader__left {
        flex: 1 1 auto;
        min-width: 0;
    }

    .brain-subheader__center { order: 3; }

    /* Right side becomes a full-width row underneath the title */
    .brain-subheader__right {
        order: 4;
        flex: 0 0 100%;
        width: 100%;
        gap: 6px;
        justify-content: flex-start;
    }

    .brain-subheader__action-btn { padding: 6px 12px; font-size: 0.72rem; }

    /* Show Chat/Studio switcher inside subheader on mobile
       (topbar version is hidden via common.css ≤768px) */
    .brain-subheader__mode-switcher {
        display: flex;
    }

    /* Push action buttons to the right end of the row */
    .brain-subheader__action-btn--new {
        margin-left: auto;
    }

    .recent-chats { display: none; }

    .chat-msg { padding: 6px 16px; }
    .chat-msg--user .chat-msg__content { max-width: 85%; }
    .chat-input-area { padding: 0 16px calc(14px + env(safe-area-inset-bottom, 0px)); }
    .chat-typing { padding: 6px 16px; }
    .chat-input-wrapper {
        gap: 8px;
        padding: 8px 8px 8px 10px;
    }
    .chat-voice-btn {
        height: 42px;
        padding: 0 14px 0 10px;
    }

    .chat-welcome { padding: 32px 20px; }
    .chat-welcome__brain { width: 56px; height: 56px; border-radius: 12px; }
    .chat-welcome__brain svg { width: 32px; height: 32px; }
    .chat-welcome__title { font-size: 1.3rem; }
    .chat-welcome__suggestions { grid-template-columns: 1fr; max-width: 340px; }
}

@media (max-width: 480px) {
    .brain-subheader__center { display: none; }
    .brain-subheader__subtitle { display: none; }
    /* Icon-only action buttons on very small screens */
    .brain-subheader__action-btn span { display: none; }
    .brain-subheader__action-btn { padding: 7px 10px; }
    .brain-subheader__action-btn svg { width: 16px; height: 16px; }
    .chat-msg { padding: 4px 12px; }
    .chat-send-btn { width: 38px; height: 38px; }
    .chat-input-area { padding: 0 10px calc(12px + env(safe-area-inset-bottom, 0px)); }
    .chat-composer-shell { gap: 8px; }
    .chat-attachment-chip { width: 100%; }
    .chat-attachment-chip__name { max-width: 100%; }
    .chat-voice-btn {
        padding: 0 12px 0 10px;
    }
    .chat-voice-btn__label {
        display: none;
    }

    .voice-visualizer-container,
    .voice-visualizer {
        width: 80px;
        min-width: 80px;
        max-width: 80px;
    }

    /* Remove avatar on very small screens */
    .chat-msg--assistant .chat-msg__content-inner { padding-left: 0; }
    .chat-msg--assistant .chat-msg__content-inner::before { display: none; }
    .chat-typing__bubble { padding-left: 0; }
    .chat-typing__bubble::before { display: none; }

    .chat-welcome__orb { display: none; }
}

@media (max-width: 375px) {
    .chat-quick-prompt {
        font-size: 0.7rem;
        padding: 7px 10px;
        white-space: normal;
    }
}

/* -----------------------------------------------------
   �17  UTILITY
   ----------------------------------------------------- */
.hidden { display: none !important; }

/* -----------------------------------------------------
   �18  TOAST NOTIFICATION
   ----------------------------------------------------- */
.lp-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 11px 20px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
    z-index: 10000;
    animation: toastSlideIn 0.3s ease;
    box-shadow: 0 1px 4px rgba(0,0,0,0.03);
}

.lp-toast--success { background: var(--color-success); }
.lp-toast--error { background: var(--color-error); }
.lp-toast--info { background: var(--color-primary); }

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}




