/* Chat-first page — aligns with dashboard tokens */
.chat-page {
    --chat-sidebar-w: clamp(200px, 32vw, 300px);
    --ln-app-bg-start: #667eea;
    --ln-app-bg-end: #764ba2;
    --ln-app-surface: rgba(255, 255, 255, 0.94);
    --ln-app-surface-border: rgba(255, 255, 255, 0.46);
    --ln-app-surface-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
    /* Lock page to viewport so inner flex + #chatMessagesWrap become the scroll container (not the window). */
    height: 100vh;
    max-height: 100vh;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 16px;
    background: linear-gradient(135deg, var(--ln-app-bg-start) 0%, var(--ln-app-bg-end) 100%);
    color: #111827;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
}

@supports (height: 100dvh) {
    .chat-page {
        height: 100dvh;
        max-height: 100dvh;
    }
}

.chat-shell {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    background: var(--ln-app-surface);
    border: 1px solid var(--ln-app-surface-border);
    border-radius: 18px;
    box-shadow: var(--ln-app-surface-shadow);
    backdrop-filter: blur(6px);
    padding-top: 12px;
    padding-bottom: 10px;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: calc(var(--chat-sidebar-w) + 20px + env(safe-area-inset-right, 0px));
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    box-sizing: border-box;
}

.chat-top {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin: 0 4px 12px;
    padding: 0 2px 12px;
    border-bottom: 1px solid #e6e9ef;
}

.chat-primary-nav {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 8px;
    font-size: 14px;
}

.chat-primary-nav-current {
    color: #0f172a;
    font-weight: 700;
    border-bottom: 3px solid #2563eb;
    padding-bottom: 4px;
    line-height: 1.2;
}

.chat-primary-nav-link {
    color: #6b7280;
    text-decoration: none;
    font-weight: 500;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    border-bottom: 3px solid transparent;
    padding-bottom: 4px;
    line-height: 1.2;
    transition: color 0.18s ease, border-bottom-color 0.18s ease;
}

.chat-primary-nav-link:hover,
.chat-primary-nav-link:focus-visible {
    color: #334155;
    border-bottom-color: #93c5fd;
    outline: none;
}

.chat-top h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.chat-head-intro {
    min-width: 0;
}

.chat-page-title {
    margin: 0;
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #1f2937;
}

.chat-page-subtitle {
    margin: 4px 0 0;
    font-size: 0.88rem;
    color: #64748b;
}

.chat-top-icons {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: center;
    margin-left: auto;
}

.chat-header-actions-wrap {
    position: relative;
    order: 1;
}

#canvasNavToggle {
    order: 2;
}

.chat-top-icons #canvasNavToggle.canvas-nav-toggle {
    position: static;
    top: auto;
    right: auto;
    box-shadow: none;
}

#chatSidebarToggle {
    order: 3;
}

.chat-header-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.chat-header-icon-btn:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.chat-header-icon-btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.chat-header-actions-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 1100;
    min-width: 240px;
    padding: 10px;
    background: #fff;
    border: 1px solid #e6e9ef;
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
}

.chat-header-menu-btn,
.chat-header-menu-link {
    width: 100%;
    min-height: 40px;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    margin: 0 0 6px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #1f2937;
    text-align: left;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
}

.chat-header-menu-btn:hover,
.chat-header-menu-btn:focus-visible,
.chat-header-menu-link:hover,
.chat-header-menu-link:focus-visible {
    background: #f8fafc;
    border-color: #cbd5e1;
    outline: none;
}

.chat-header-menu-link:last-child,
.chat-header-menu-btn:last-child {
    margin-bottom: 0;
}

.chat-model-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 200px;
}

.chat-model-field label {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
}

.chat-model-field select {
    min-height: 44px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #fff;
    font-size: 14px;
}

.chat-model-hint {
    font-size: 11px;
    color: #6b7280;
    max-width: 280px;
    line-height: 1.35;
}

.chat-model-field--menu {
    min-width: 0;
    margin: 4px 0 8px;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
}

/* Grid gives .chat-main a definite height so inner flex (messages + sticky composer) can scroll.
   minmax(0, 1fr) avoids a content-sized column on first paint (1fr’s implicit min is auto), which
   made the thread look narrow until reflow (e.g. typing in the composer). */
.chat-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    flex: 1 1 0;
    width: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.chat-main {
    grid-row: 1;
    grid-column: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: 0;
    box-sizing: border-box;
    border: 1px solid #e6e9ef;
    border-radius: 14px;
    background: rgba(248, 250, 252, 0.72);
    padding: 10px;
}

.chat-sidebar-panel {
    /* Same grid cell as main (fixed panel does not consume a second row). */
    grid-row: 1;
    grid-column: 1;
    position: fixed;
    top: calc(16px + env(safe-area-inset-top, 0));
    right: calc(16px + env(safe-area-inset-right, 0));
    bottom: calc(16px + env(safe-area-inset-bottom, 0));
    width: var(--chat-sidebar-w);
    max-width: var(--chat-sidebar-w);
    z-index: 100;
    background: var(--ln-sidebar-bg, #fff);
    border: 1px solid var(--ln-sidebar-border, #e6e9ef);
    border-right: 1px solid var(--ln-sidebar-border, #e6e9ef);
    border-radius: 14px;
    padding: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    box-shadow: var(--ln-sidebar-shadow, -8px 0 28px rgba(15, 23, 42, 0.12));
}

.chat-sidebar-panel h2 {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ln-sidebar-title, #6b7280);
    margin: 16px 0 8px;
}

.chat-sidebar-panel h2:first-child {
    margin-top: 0;
}

.canvas-chat-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: -2px -2px 10px;
    padding: 2px 2px 10px;
    border-bottom: 1px solid var(--ln-sidebar-border, #e6e9ef);
}

.canvas-chat-sidebar-head h2 {
    margin: 0;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ln-sidebar-title, #6b7280);
    font-weight: 600;
}

.canvas-chat-sidebar-close {
    width: 36px;
    height: 36px;
    border: 1px solid var(--ln-sidebar-card-border, #d1d5db);
    border-radius: 10px;
    background: var(--ln-sidebar-card-bg, #f9fafb);
    color: #475569;
    cursor: pointer;
    line-height: 1;
    font-size: 20px;
    flex-shrink: 0;
}

.canvas-chat-sidebar-close:hover {
    background: var(--ln-sidebar-card-hover, #f1f5f9);
    border-color: var(--ln-sidebar-card-hover-border, #cbd5e1);
    color: #111827;
}

.chat-page .chat-sidebar-panel .canvas-chat-sidebar-close {
    display: none;
}

.sidebar-filter {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--ln-sidebar-card-border, #d1d5db);
    margin-bottom: 6px;
    font-size: 14px;
}

.chat-filter-row {
    position: relative;
    margin-bottom: 6px;
}

.chat-filter-row-inner {
    display: flex;
    align-items: stretch;
    gap: 6px;
}

.chat-filter-toggle {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    min-height: 38px;
    padding: 0;
    border: 1px solid var(--ln-sidebar-card-border, #d1d5db);
    border-radius: 10px;
    background: var(--ln-sidebar-card-bg, #f9fafb);
    color: #374151;
    cursor: pointer;
    box-sizing: border-box;
}

.chat-filter-toggle:hover {
    background: var(--ln-sidebar-card-hover, #f1f5f9);
    border-color: var(--ln-sidebar-card-hover-border, #9ca3af);
}

.chat-filter-toggle:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.chat-filter-icon {
    display: block;
}

.chat-filter-search.sidebar-filter {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.chat-filter-panel {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 1001;
    max-width: 100%;
    box-sizing: border-box;
    padding: 12px;
    background: var(--ln-sidebar-bg, #fff);
    border: 1px solid var(--ln-sidebar-border, #e6e9ef);
    border-radius: 10px;
    box-shadow:
        0 8px 28px rgba(15, 23, 42, 0.12),
        0 2px 8px rgba(15, 23, 42, 0.06);
}

.chat-filter-panel-hint {
    font-size: 11px;
    color: #6b7280;
    line-height: 1.35;
    margin: 0 0 10px;
}

.chat-filter-field {
    margin-bottom: 10px;
}

.chat-filter-field:last-of-type {
    margin-bottom: 0;
}

.chat-filter-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #4b5563;
    margin-bottom: 4px;
}

.chat-filter-select,
.chat-filter-date {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    font-size: 13px;
    background: #fff;
}

/* Date inputs often render huge text vs. <select>; tighten size and WebKit internals. */
.chat-filter-date {
    font-size: 12px;
    line-height: 1.3;
    padding: 5px 6px;
    min-height: 32px;
}

.chat-filter-date::-webkit-datetime-edit,
.chat-filter-date::-webkit-datetime-edit-fields-wrapper {
    padding: 0;
}

.chat-filter-date::-webkit-datetime-edit-text {
    padding: 0 0.2em;
    color: #111827;
}

.chat-filter-date::-webkit-datetime-edit-month-field,
.chat-filter-date::-webkit-datetime-edit-day-field,
.chat-filter-date::-webkit-datetime-edit-year-field {
    font-size: 12px;
    line-height: 1.3;
    padding: 0 1px;
}

.chat-filter-date::-webkit-calendar-picker-indicator {
    margin-left: 2px;
    transform: scale(0.85);
    transform-origin: right center;
    cursor: pointer;
}

.chat-filter-dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.chat-filter-dates .chat-filter-field {
    margin-bottom: 0;
    min-width: 0;
}

.chat-filter-panel-actions {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #f0f2f5;
}

.chat-filter-reset {
    width: 100%;
}

.chat-filter-hint {
    font-size: 11px;
    color: #6b7280;
    line-height: 1.35;
    margin: 0 0 10px;
}

.sidebar-section {
    border-bottom: 1px solid var(--ln-sidebar-border, #f0f2f5);
    padding-bottom: 4px;
    margin-bottom: 4px;
}

.sidebar-section:last-child {
    border-bottom: none;
}

.sidebar-section-toggle {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    text-align: left;
    background: transparent;
    border: none;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ln-sidebar-title, #6b7280);
    padding: 10px 4px;
    margin: 0;
    cursor: pointer;
    min-height: 44px;
    box-sizing: border-box;
}

.sidebar-section-toggle:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
    border-radius: 6px;
}

.sidebar-section-title {
    flex: 1;
}

.sidebar-chevron {
    display: inline-block;
    font-size: 10px;
    color: var(--ln-sidebar-muted, #9ca3af);
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.sidebar-section-toggle[aria-expanded="false"] .sidebar-chevron {
    transform: rotate(-90deg);
}

.sidebar-section-body {
    padding-bottom: 8px;
}

.sidebar-section-body.collapsed {
    display: none;
}

.sidebar-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-list li {
    margin-bottom: 8px;
}

.sidebar-link {
    display: block;
    padding: 10px 8px;
    border-radius: 10px;
    background: var(--ln-sidebar-card-bg, #f9fafb);
    border: 1px solid var(--ln-sidebar-card-border, #e5e7eb);
    color: var(--ln-sidebar-text, #111827);
    text-decoration: none;
    font-size: 13px;
    line-height: 1.35;
    min-height: 44px;
    box-sizing: border-box;
}

.sidebar-link:hover,
.sidebar-link:focus-visible {
    background: var(--ln-sidebar-card-hover, #f1f5f9);
    border-color: var(--ln-sidebar-card-hover-border, #cbd5e1);
    outline: none;
}

button.sidebar-link,
a.sidebar-link {
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.sidebar-muted {
    font-size: 12px;
    color: #6b7280;
    padding: 8px 4px;
}

.sidebar-drawer-toggle {
    display: none;
    min-width: 44px;
    min-height: 44px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #fff;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.sidebar-drawer-toggle:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.chat-messages-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 8px 6px 12px;
    position: relative;
    z-index: 1;
}

/* Filter still applies to the thread; banner hidden per product preference. */
.chat-active-filter-bar {
    display: none !important;
}

.chat-active-filter-label {
    font-weight: 600;
    color: #713f12;
}

.chat-active-filter-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid #eab308;
    color: #422006;
    font-weight: 500;
    max-width: min(100%, 280px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-active-filter-clear {
    min-height: 44px;
    min-width: 44px;
    padding: 8px 14px;
    margin-left: auto;
    border-radius: 8px;
    border: 1px solid #ca8a04;
    background: #fff;
    color: #713f12;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.chat-active-filter-clear:hover,
.chat-active-filter-clear:focus-visible {
    background: #fef9c3;
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.chat-thread-filter-empty {
    font-size: 13px;
    color: #6b7280;
    text-align: center;
    padding: 16px 12px;
    background: #fff;
    border: 1px dashed #d1d5db;
    border-radius: 10px;
    margin-bottom: 10px;
}

.chat-processing-banner {
    font-size: 13px;
    color: #374151;
    padding: 12px 14px;
    margin-top: 8px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
}

.chat-welcome {
    background: #fff;
    border: 1px solid #e6e9ef;
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 12px;
}

.chat-welcome p {
    margin: 0 0 10px;
    font-size: 14px;
    line-height: 1.5;
    color: #374151;
}

.suggested-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.suggested-prompts button {
    min-height: 44px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid #c7d2fe;
    background: #f8faff;
    color: #2f3b8f;
    font-size: 13px;
    cursor: pointer;
}

.suggested-prompts button:hover,
.suggested-prompts button:focus-visible {
    background: #eef2ff;
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.chat-msg {
    position: relative;
    max-width: 85%;
    margin-bottom: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.45;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.chat-msg .msg-body {
    overflow-wrap: anywhere;
}

.chat-msg.user {
    margin-left: auto;
    background: #dbeafe;
    border: 1px solid #bfdbfe;
}

.chat-msg.assistant {
    margin-right: auto;
    background: #fff;
    border: 1px solid #e6e9ef;
}

.chat-msg.assistant .msg-body .msg-md-p {
    margin: 0 0 0.55em;
}

.chat-msg.assistant .msg-body .msg-md-p:last-child {
    margin-bottom: 0;
}

.chat-msg.assistant .msg-body strong {
    font-weight: 600;
    color: #1e293b;
}

.chat-msg.assistant .msg-body .msg-md-pre {
    margin: 0.55em 0;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #f1f5f9;
    overflow-x: auto;
    max-width: 100%;
    box-sizing: border-box;
}

.chat-msg.assistant .msg-body .msg-md-pre:first-child {
    margin-top: 0;
}

.chat-msg.assistant .msg-body .msg-md-pre:last-child {
    margin-bottom: 0;
}

.chat-msg.assistant .msg-body .msg-md-code {
    display: block;
    margin: 0;
    padding: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
    font-size: 0.82rem;
    line-height: 1.45;
    white-space: pre;
    color: #0f172a;
    background: transparent;
}

.chat-msg.assistant .msg-body blockquote.chat-pullquote {
    position: relative;
    margin: 0.65em 0;
    padding: 12px 14px 12px 16px;
    border-radius: 10px;
    border: 1px solid #e6e9ef;
    background: linear-gradient(135deg, #f8fafc 0%, #fff 55%);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.chat-msg.assistant .msg-body blockquote.chat-pullquote--quote::before {
    content: '"';
    position: absolute;
    left: 10px;
    top: 6px;
    font-size: 2rem;
    line-height: 1;
    font-family: Georgia, 'Times New Roman', serif;
    color: rgba(37, 99, 235, 0.35);
    pointer-events: none;
}

.chat-msg.assistant .msg-body blockquote.chat-pullquote--scripture {
    padding-left: 18px;
    background: linear-gradient(135deg, rgba(180, 140, 60, 0.08) 0%, #fff 50%);
    border-color: rgba(180, 140, 60, 0.35);
}

.chat-msg.assistant .msg-body blockquote.chat-pullquote--scripture::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    border-radius: 10px 0 0 10px;
    background: linear-gradient(180deg, #c4a35a 0%, #a67c3a 100%);
    pointer-events: none;
}

.chat-msg.assistant .msg-body .chat-pullquote-text {
    position: relative;
    z-index: 1;
    margin: 0;
    padding-left: 0.35rem;
    font-family: Georgia, 'Palatino Linotype', Palatino, 'Times New Roman', serif;
    font-size: 0.98em;
    line-height: 1.55;
    color: #1e293b;
}

.chat-msg.assistant .msg-body blockquote.chat-pullquote--scripture .chat-pullquote-text {
    padding-left: 0.5rem;
}

.chat-msg.assistant .msg-body .chat-pullquote-attrib {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #e6e9ef;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #64748b;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.msg-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
    min-height: 22px;
}

.msg-footer-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.chat-msg-meta {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: #94a3b8;
    margin-top: 0;
    opacity: 0.72;
    font-variant-numeric: tabular-nums;
}

.msg-saved-chip {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #047857;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    padding: 2px 8px;
    border-radius: 999px;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.msg-saved-chip--out {
    opacity: 0;
}

.msg-actions-wrap {
    position: relative;
    flex-shrink: 0;
    align-self: flex-end;
    display: flex;
    align-items: center;
    gap: 2px;
}

.msg-tts-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin: 0 -2px -2px 0;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.18s ease, background-color 0.15s ease, color 0.15s ease;
    color: #64748b;
}

.msg-tts-btn .msg-tts-icon {
    display: block;
}

.msg-tts-btn:focus-visible {
    opacity: 1;
    outline: 2px solid #2563eb;
    outline-offset: 1px;
}

.msg-tts-btn:hover {
    background: rgba(0, 0, 0, 0.04);
}

.msg-tts-btn--playing {
    opacity: 1;
    color: #4f46e5;
    background: rgba(99, 102, 241, 0.12);
}

.msg-tts-btn--playing:hover {
    background: rgba(99, 102, 241, 0.18);
}

@media (hover: hover) {
    .msg-tts-btn {
        opacity: 0.28;
    }

    .chat-msg:hover .msg-tts-btn {
        opacity: 1;
    }
}

.msg-actions-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin: 0 -4px -2px 0;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.18s ease, background-color 0.15s ease;
    font-size: 17px;
    line-height: 1;
    color: #64748b;
}

@media (hover: hover) {
    .msg-actions-trigger {
        opacity: 0.28;
    }

    .chat-msg:hover .msg-actions-trigger {
        opacity: 1;
    }
}

.chat-msg.user .msg-actions-trigger {
    color: #3b6fd9;
}

/* Midline horizontal ellipsis — compact “more” affordance (avoids emoji / heavy +). */
.msg-actions-trigger::before {
    display: inline-block;
    content: '\22EF';
    font-size: 15px;
    line-height: 1;
    letter-spacing: 0.04em;
    font-weight: 600;
    transform: translateY(-0.5px);
}

.msg-actions-trigger:focus-visible,
.msg-actions-trigger--open {
    opacity: 1;
}

.msg-actions-trigger:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 1px;
}

.msg-actions-trigger:hover {
    background: rgba(0, 0, 0, 0.04);
}

.chat-msg.user .msg-actions-trigger:hover {
    background: rgba(255, 255, 255, 0.45);
}

.msg-actions-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    bottom: auto;
    min-width: 168px;
    padding: 4px 0;
    margin: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    z-index: 40;
}

.msg-actions-menu-item {
    display: block;
    padding: 8px 14px;
    font-size: 13px;
    color: #1e293b;
    text-decoration: none;
    white-space: nowrap;
}

.msg-actions-menu-item:hover,
.msg-actions-menu-item:focus-visible {
    background: #f1f5f9;
    outline: none;
}

.chat-msg.unprocessed {
    border-color: #fcd34d;
    box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.35);
}

.msg-unprocessed-hint {
    font-size: 13px;
    color: #92400e;
    line-height: 1.45;
    margin-top: 8px;
    padding: 8px 10px;
    background: #fffbeb;
    border-radius: 8px;
    border: 1px solid #fcd34d;
}

.msg-retry-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.sidebar-object-type-btn {
    position: relative;
    padding-left: 36px !important;
}

.sidebar-object-type-btn::before {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    line-height: 1;
}

.sidebar-object-type--task::before { content: '\2713'; }
.sidebar-object-type--fitness_log::before { content: '\26F3'; }
.sidebar-object-type--meeting::before { content: '\1F4C5'; }
.sidebar-object-type--expense::before { content: '\0024'; }
.sidebar-object-type--journal_entry::before { content: '\1F4D6'; }
.sidebar-object-type--note::before { content: '\1F4DD'; }
.sidebar-object-type--default::before { content: '\2022'; }

.sidebar-object-type-btn.sidebar-object-type--task,
.sidebar-object-type-btn.sidebar-object-type--fitness_log,
.sidebar-object-type-btn.sidebar-object-type--meeting,
.sidebar-object-type-btn.sidebar-object-type--expense,
.sidebar-object-type-btn.sidebar-object-type--journal_entry,
.sidebar-object-type-btn.sidebar-object-type--note {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #14532d;
}

.sidebar-object-type-btn.sidebar-object-type--default {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e3a5f;
}

.chat-msg-pending-badge {
    display: inline-block;
    margin-top: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #1d4ed8;
    background: #dbeafe;
    padding: 4px 10px;
    border-radius: 999px;
}

.msg-retry-btn {
    margin-top: 8px;
    min-height: 40px;
    padding: 8px 14px;
    font-size: 13px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #fff;
    cursor: pointer;
}

.msg-retry-btn:hover,
.msg-retry-btn:focus-visible {
    background: #f3f4f6;
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.load-older-wrap {
    text-align: center;
    margin-bottom: 12px;
}

.chat-load-more-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 12px;
}

.chat-msg--highlight {
    animation: chatMsgHighlight 2s ease-out forwards;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.45);
    border-radius: 12px;
}

@keyframes chatMsgHighlight {
    0% {
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.55);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
    }
}

.typing-indicator {
    display: none;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #6b7280;
    padding: 6px 12px;
    margin-bottom: 8px;
}

.typing-indicator.active {
    display: flex;
}

.typing-dots span {
    animation: chatDot 1.2s infinite ease-in-out both;
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 3px;
    border-radius: 50%;
    background: #9ca3af;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatDot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.chat-composer-sticky {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, rgba(248, 250, 252, 0) 0%, rgba(248, 250, 252, 0.96) 22%);
    padding: 10px 0 16px;
    margin-top: auto;
}

.chat-status-bar {
    font-size: 13px;
    color: #4b5563;
    min-height: 1.25em;
    margin-bottom: 6px;
}

.chat-status-bar.error {
    color: #b91c1c;
}

.composer-inner {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: #fff;
    border: 1px solid #e6e9ef;
    border-radius: 10px;
    padding: 10px;
}

.chat-composer-sticky textarea {
    flex: 1;
    min-width: 0;
    min-height: 88px;
    max-height: 240px;
    resize: vertical;
    border: none;
    font-size: 15px;
    font-family: inherit;
    line-height: 1.45;
}

.chat-composer-sticky textarea:focus {
    outline: none;
}

.composer-inner:focus-within {
    border-color: #93c5fd;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

#chatVoiceBtn,
#chatSendBtn {
    min-width: 44px;
    min-height: 44px;
    flex-shrink: 0;
}

.chat-voice-btn {
    padding: 0.5rem 0.65rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.chat-voice-btn .chat-voice-icon {
    display: block;
}

.chat-voice-btn.chat-voice-btn--listening {
    background: #fecaca;
    color: #b91c1c;
    border-color: #f87171;
}

.chat-voice-btn.chat-voice-btn--listening:hover {
    background: #fca5a5;
    color: #991b1b;
    transform: translateY(-1px);
}

.chat-voice-btn:disabled,
.chat-voice-btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.chat-voice-btn.chat-voice-btn--unsupported {
    opacity: 0.55;
    cursor: not-allowed;
}

.composer-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.composer-meta-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.chat-voice-mode-btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-voice-mode-btn--on {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border-color: transparent;
}

.chat-voice-mode-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

body.chat-voice-mode-on .msg-tts-btn {
    display: none !important;
}

.char-count-chat {
    font-size: 12px;
    color: #6b7280;
    line-height: 1;
}

.char-count-chat.warn { color: #b45309; }
.char-count-chat.err { color: #b91c1c; font-weight: 600; }

.chat-retry-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.chat-retry-icon-btn:hover,
.chat-retry-icon-btn:focus-visible {
    background: #e2e8f0;
    color: #0f172a;
    outline: none;
}

.chat-retry-icon-btn:focus-visible {
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #2563eb;
}

.toast-chat {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #111827;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 10060;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.toast-chat.show {
    opacity: 1;
    pointer-events: auto;
}

/* Desktop: fixed sidebar always visible; backdrop and sidebar toggle hidden. */
@media (min-width: 769px) {
    .drawer-backdrop,
    .drawer-backdrop.open {
        display: none !important;
        pointer-events: none !important;
    }

    .sidebar-drawer-toggle {
        display: none !important;
    }

    .chat-sidebar-panel {
        transform: none;
    }

    .chat-sidebar-panel.open {
        transform: none;
    }
}

/* Mobile: off-canvas sidebar, backdrop, visible drawer toggle */
@media (max-width: 768px) {
    .chat-page {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
    }

    .chat-shell {
        border-radius: 14px;
        padding-right: max(16px, env(safe-area-inset-right, 0px));
    }

    .chat-top {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .chat-top-icons {
        margin-left: 0;
        justify-content: flex-end;
        align-self: flex-end;
    }

    .chat-header-actions-menu {
        right: 0;
        left: auto;
        width: min(92vw, 300px);
        min-width: 0;
    }

    .chat-model-field--menu {
        width: 100%;
    }

    .chat-main {
        min-width: 0;
        width: 100%;
    }

    /* Textarea full width; mic + Send share one row (saves height, matches desktop affordance). */
    .composer-inner {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: stretch;
    }

    .chat-composer-sticky .composer-inner > textarea {
        flex: 1 1 100%;
        width: 100%;
        min-width: 0;
    }

    #chatVoiceBtn,
    #chatSendBtn {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
    }

    .drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.38);
        z-index: 1010;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.2s ease, visibility 0.2s ease;
    }

    .drawer-backdrop.open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .sidebar-drawer-toggle {
        display: inline-flex !important;
    }

    .chat-sidebar-panel {
        top: calc(10px + env(safe-area-inset-top, 0));
        right: env(safe-area-inset-right, 0);
        bottom: calc(10px + env(safe-area-inset-bottom, 0));
        width: min(320px, 88vw);
        max-width: min(320px, 88vw);
        z-index: 1020;
        border-radius: 14px 0 0 14px;
        border-right: none;
        transform: translateX(100%);
        transition: transform 0.2s ease;
        pointer-events: none;
    }

    .chat-sidebar-panel.open {
        transform: translateX(0);
        pointer-events: auto;
    }

    .chat-page .chat-sidebar-panel .canvas-chat-sidebar-close {
        display: inline-flex;
    }
}

/* Conversation threads */
.chat-conversations-block {
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--ln-sidebar-border, #e6e9ef);
}

.chat-conversations-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-conversations-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ln-sidebar-title, #6b7280);
    margin: 0;
    font-weight: 600;
}

.chat-new-thread-btn {
    flex-shrink: 0;
    padding: 6px 10px;
    font-size: 12px;
    min-height: 36px;
}

.chat-thread-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 220px;
    overflow-y: auto;
}

.chat-thread-item {
    margin: 0 0 4px;
}

.chat-thread-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    text-align: left;
    padding: 10px 10px;
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid var(--ln-sidebar-card-border, #e5e7eb);
    background: var(--ln-sidebar-card-bg, #f9fafb);
    font-size: 13px;
    line-height: 1.3;
    color: #1f2937;
    cursor: pointer;
    overflow: hidden;
}

.chat-thread-btn-title {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-thread-continued-hint {
    font-size: 11px;
    font-weight: 400;
    color: #6b7280;
    line-height: 1.25;
}

.chat-thread-item--active .chat-thread-btn {
    border-color: var(--ln-sidebar-active-border, #c7d2fe);
    background: var(--ln-sidebar-active-bg, #eef2ff);
    color: var(--ln-sidebar-active-text, #3730a3);
    font-weight: 600;
}

.chat-thread-btn:hover {
    border-color: var(--ln-sidebar-card-hover-border, #cbd5e1);
    background: var(--ln-sidebar-card-hover, #f1f5f9);
}

.chat-thread-empty {
    font-size: 12px;
    color: #6b7280;
    padding: 8px 4px;
}

/* AI agents bar — z-index above .chat-messages-wrap so the Add-agent popover (absolute, extends downward) receives clicks */
.chat-agents-bar {
    position: relative;
    z-index: 10;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.chat-agents-bar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.chat-agents-label {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}

.chat-agent-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 120px;
}

.chat-agent-none {
    font-size: 13px;
    color: #6b7280;
}

.chat-agent-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    font-size: 13px;
}

.chat-agent-chip-name {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-agent-chip-controls {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.chat-agent-chip-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
    color: #475569;
}

.chat-agent-chip-btn:hover,
.chat-agent-chip-btn:focus-visible {
    background: rgba(0, 0, 0, 0.06);
    outline: none;
}

.chat-agent-chip-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.chat-agent-chip-btn--remove {
    font-weight: 700;
    font-size: 14px;
}

.chat-agent-chip-btn--edit {
    font-size: 11px;
}

.chat-agents-btn {
    font-size: 13px;
}

.chat-thread-custom-details {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
}

.chat-thread-custom-summary {
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #2563eb;
}

.chat-thread-custom-hint {
    font-size: 12px;
    color: #6b7280;
    margin: 6px 0 8px;
}

.chat-thread-custom-ta {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    min-height: 52px;
    margin-bottom: 8px;
}

.chat-agent-popover {
    position: absolute;
    left: 0;
    top: 100%;
    margin-top: 6px;
    min-width: min(320px, 100%);
    max-width: 100%;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
    z-index: 20;
}

.chat-agent-popover-head {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
}

.chat-agent-popover-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-agent-popover-name {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-agent-popover-empty {
    font-size: 12px;
    color: #6b7280;
    margin: 0 0 8px;
}

.chat-agent-popover-create {
    width: 100%;
    margin-top: 4px;
}

.msg-actions-menu-btn {
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
}

.chat-agent-modal-root {
    position: fixed;
    inset: 0;
    /* Above sidebar/drawer/filter; below app hamburger (10050) and toast (.toast-chat 10060) */
    z-index: 10040;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}

.chat-agent-modal-root[hidden] {
    display: none !important;
}

.chat-agent-modal-backdrop {
    position: absolute;
    inset: 0;
    border: none;
    padding: 0;
    margin: 0;
    background: rgba(15, 23, 42, 0.45);
    cursor: pointer;
}

.chat-agent-modal-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow: auto;
    background: #fff;
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.2);
}

.chat-agent-modal-title {
    margin: 0 0 16px;
    font-size: 1.15rem;
}

.chat-agent-modal-body label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-top: 10px;
    margin-bottom: 4px;
}

.chat-agent-modal-body label:first-of-type {
    margin-top: 0;
}

.chat-agent-modal-body .optional {
    font-weight: 400;
    color: #6b7280;
}

.chat-agent-modal-hint {
    font-size: 12px;
    color: #6b7280;
    margin: 0 0 6px;
}

.chat-agent-modal-input,
.chat-agent-modal-ta {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
}

.chat-agent-modal-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 13px;
    font-weight: 500;
}

.chat-agent-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

/* Google Docs pending replace */
.chat-google-doc-confirm {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
}

.chat-google-doc-confirm-preview {
    margin: 0 0 8px;
    font-size: 12px;
    color: #374151;
    line-height: 1.4;
    max-height: 4.5em;
    overflow: hidden;
}

.chat-google-doc-confirm-btn {
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
}

.chat-google-doc-confirm-btn:hover:not(:disabled) {
    background: #1d4ed8;
}

.chat-google-doc-confirm-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
