/* ============================================
   OCC Chatbot Widget - Modern CSS
   Organized and maintainable stylesheet
   ============================================ */

/* ========== CSS Variables ========== */
:root {
    /* Colors */
    --primary-color: #00838e;
    --primary-dark: #006570;
    --primary-light: #e0f2fe;
    --secondary-color: #ff9800;
    --secondary-dark: #f57c00;

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-white: #ffffff;

    --bg-white: #ffffff;
    --bg-gray-50: #f8f9fa;
    --bg-gray-100: #f3f4f6;
    --bg-gray-200: #e5e7eb;

    --border-color: #e5e7eb;
    --border-color-dark: #d1d5db;

    --success-color: #28a745;
    --success-dark: #218838;
    --error-color: #dc3545;
    --warning-color: #ffc107;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 12px 32px rgba(0, 0, 0, 0.15);

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;

    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;

    /* Z-Index */
    --z-overlay: 9998;
    --z-widget: 9999;
    --z-sidebar: 99998;
}

/* Dark Mode Variables */
.dark-mode {
    --bg-white: #18181b;
    --bg-gray-50: #27272a;
    --bg-gray-100: #3f3f46;
    --bg-gray-200: #52525b;

    --text-primary: #f3f4f6;
    --text-secondary: #a1a1aa;

    --border-color: #3f3f46;
    --border-color-dark: #52525b;
}

/* Dark Mode Component Overrides */
.dark-mode .faq-toggle {
    color: var(--text-primary);
}

.dark-mode .faq-text {
    color: var(--text-secondary);
}

.dark-mode .message.user .message-content {
    background: linear-gradient(135deg, #0e7490 0%, #0891b2 100%);
    color: #f0f9ff;
}

.dark-mode .tip-box {
    background: linear-gradient(135deg, rgba(14, 116, 144, 0.3) 0%, rgba(8, 145, 178, 0.3) 100%);
    border-left-color: #06b6d4;
}

.dark-mode .tip-title {
    color: #67e8f9;
}

.dark-mode .tip-text {
    color: #e0f2fe;
}

.dark-mode .tip-icon {
    color: #67e8f9;
}

/* ========== Base Styles ========== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: transparent;
    min-height: 0;
    min-width: 0;
    overflow: visible;
}

/* Hide scrollbar for clean look */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--border-color-dark);
}

/* ========== Utility Classes ========== */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ========== Overlay ========== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-overlay);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.overlay.active {
    opacity: 1;
}

/* ========== Chat Widget Container ========== */
.chat-widget {
    position: fixed;
    bottom: var(--spacing-lg);
    right: var(--spacing-lg);
    z-index: var(--z-widget);
    transition: all var(--transition-normal);
}

/* ========== Widget Button (Minimized State) ========== */
.widget-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--text-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-fast);
    position: relative;
}

.widget-btn:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-xl);
}

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

.widget-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: var(--error-color);
    color: var(--text-white);
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    box-shadow: var(--shadow-sm);
}

/* ========== Chat Panel ========== */
.chat-panel {
    width: 600px;
    height: 700px;
    max-width: 95vw;
    max-height: 85vh;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all var(--transition-normal);
}

/* Fullscreen State */
.chat-widget.fullscreen {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
    width: 100vw !important;
    height: 100vh !important;
}

.chat-widget.fullscreen .chat-panel {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
}

/* Fullscreen: Centered content like ChatGPT/Claude */
.chat-widget.fullscreen .chat-messages {
    --content-max-width: 900px;
    padding-left: max(var(--spacing-lg), calc((100% - var(--content-max-width)) / 2));
    padding-right: max(var(--spacing-lg), calc((100% - var(--content-max-width)) / 2));
}

.chat-widget.fullscreen .message {
    max-width: 100%;
}

.chat-widget.fullscreen .message.user {
    max-width: 75%;
}

.chat-widget.fullscreen .message.bot {
    max-width: 100%;
}

.chat-widget.fullscreen .welcome-message {
    max-width: 700px;
    align-self: center;
}

.chat-widget.fullscreen .chat-input-container {
    --content-max-width: 900px;
    padding-left: max(var(--spacing-md), calc((100% - var(--content-max-width)) / 2));
    padding-right: max(var(--spacing-md), calc((100% - var(--content-max-width)) / 2));
}

.chat-widget.fullscreen .quick-actions-container {
    --content-max-width: 900px;
    padding-left: max(var(--spacing-md), calc((100% - var(--content-max-width)) / 2));
    padding-right: max(var(--spacing-md), calc((100% - var(--content-max-width)) / 2));
}

.chat-widget.fullscreen .file-preview {
    --content-max-width: 900px;
    padding-left: max(var(--spacing-md), calc((100% - var(--content-max-width)) / 2));
    padding-right: max(var(--spacing-md), calc((100% - var(--content-max-width)) / 2));
}

/* ========== Inline citation chips + source side panel ========== */

/* Inline citation chip rendered inside the bot answer. */
.citation-chip {
    display: inline;
    font: inherit;
    color: var(--primary-color);
    background: var(--primary-light);
    border: none;
    border-radius: var(--radius-sm);
    padding: 0 4px;
    margin: 0 1px;
    cursor: pointer;
    text-decoration: underline dotted;
    text-underline-offset: 2px;
}

.citation-chip:hover {
    background: var(--primary-color);
    color: var(--text-white);
}

.citation-chip:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 1px;
}

.citation-chip[aria-current="true"],
.source-card[aria-current="true"] {
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

/* Resolved-only chip: cited but not consulted — muted, dashed, with a hint. */
.citation-chip--resolved {
    color: var(--text-secondary);
    background: var(--bg-gray-100);
    text-decoration-style: dashed;
}
.citation-chip--resolved::after {
    content: '↗';
    font-size: 0.75em;
    margin-left: 1px;
    vertical-align: super;
}
.citation-chip--resolved:hover {
    background: var(--text-secondary);
    color: var(--text-white);
}

/* Panel note shown for a resolved-only reference. */
.source-panel-note {
    display: flex;
    gap: var(--spacing-sm);
    align-items: flex-start;
    background: var(--bg-gray-100);
    border-left: 3px solid var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    margin-bottom: var(--spacing-md);
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.45;
}
.source-panel-note i {
    margin-top: 2px;
}

/* Side panel: a sibling of .chat-panel, anchored to the right of the fullscreen
   widget. Hidden by default; .source-panel-open shrinks .chat-panel to make
   room so the centred answer re-flows into the remaining width. */
.source-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(45vw, 560px);
    background: var(--bg-white);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 5;
}

.source-panel[hidden] {
    display: none;
}

/* Keyed on .source-panel-open (added to #chat-widget) so it works on both the
   fullscreen standalone widget and the app-shell Chat tab surface. */
.chat-widget.source-panel-open .chat-panel {
    width: calc(100% - min(45vw, 560px));
    transition: width 220ms ease;
}

.source-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.source-panel-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    outline: none;
    overflow-wrap: anywhere;
}

.source-panel-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    padding: var(--spacing-xs);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.source-panel-close:hover {
    background: var(--bg-gray-100);
    color: var(--text-primary);
}

.source-panel-body {
    padding: var(--spacing-md);
    overflow-y: auto;
    flex: 1;
}

.source-panel-meta h3 {
    margin: 0 0 var(--spacing-xs);
    font-size: 0.95rem;
    color: var(--text-primary);
}

.source-panel-status {
    display: inline-block;
    margin-left: var(--spacing-xs);
    padding: 1px 6px;
    font-size: 0.7rem;
    border-radius: var(--radius-sm);
    background: var(--warning-color);
    color: var(--text-primary);
    vertical-align: middle;
}

.source-panel-crumb {
    margin: 0 0 var(--spacing-md);
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.source-panel-text {
    line-height: 1.6;
    color: var(--text-primary);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

/* "Resumo" callout, mirroring search.html's preview summary. */
.source-panel-summary {
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    margin-bottom: var(--spacing-md);
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.5;
}
.source-panel-summary .label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--primary-color);
    margin-bottom: 2px;
}

/* Inline child sections for container roots (leis/decretos-lei): the root
   row has only a stub body, so the panel renders each child artigo inline. */
.source-panel-child {
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}
.source-panel-child:last-child {
    border-bottom: none;
}
.source-panel-child-title {
    margin: 0 0 4px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Reading typography for rendered legal text (mirrors .preview-reading). */
.source-panel-reading p {
    margin: 0 0 0.7em;
}
.source-panel-reading h1,
.source-panel-reading h2,
.source-panel-reading h3,
.source-panel-reading h4 {
    font-size: 0.95rem;
    margin: 1em 0 0.4em;
    color: var(--text-primary);
}
.source-panel-reading h1:first-child,
.source-panel-reading h2:first-child,
.source-panel-reading h3:first-child {
    margin-top: 0;
}
.source-panel-reading ul,
.source-panel-reading ol {
    margin: 0 0 0.7em;
    padding-left: 1.3em;
}
.source-panel-reading li {
    margin-bottom: 0.3em;
}
.source-panel-reading table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.6em 0;
    font-size: 0.82rem;
}
.source-panel-reading th,
.source-panel-reading td {
    border: 1px solid var(--border-color);
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
}
.source-panel-reading th {
    background: var(--bg-gray-50);
}

.source-panel-deeplink {
    display: inline-block;
    margin-top: var(--spacing-lg);
    font-size: 0.85rem;
    color: var(--primary-color);
}

/* Legal cross-references of the displayed artigo (clickable, open in panel). */
.source-panel-refs {
    margin-top: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    padding-top: var(--spacing-md);
}
.source-panel-refs-group {
    margin-bottom: var(--spacing-md);
}
.source-panel-refs-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}
.source-panel-refs-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}
.source-panel-ref {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
    text-align: left;
    background: var(--bg-gray-50);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    cursor: pointer;
    font: inherit;
    width: 100%;
}
.source-panel-ref:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}
.source-panel-ref:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 1px;
}
.source-panel-ref-id {
    color: var(--primary-color);
    font-weight: 600;
    font-size: 0.85rem;
}
.source-panel-ref-rel {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-white);
    background: var(--text-secondary);
    border-radius: 3px;
    padding: 1px 5px;
}
.source-panel-ref-title {
    flex-basis: 100%;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.35;
}

.source-panel-skeleton {
    height: 60vh;
    border-radius: var(--radius-md);
    background: linear-gradient(
        90deg,
        var(--bg-gray-100) 25%,
        var(--bg-gray-50) 37%,
        var(--bg-gray-100) 63%
    );
    background-size: 400% 100%;
    animation: source-panel-skel 1.2s ease infinite;
}

@keyframes source-panel-skel {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: 0 0;
    }
}

.source-panel-error {
    padding: var(--spacing-lg);
    text-align: center;
    color: var(--text-secondary);
}

.source-panel-retry {
    margin-top: var(--spacing-md);
    padding: var(--spacing-xs) var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    cursor: pointer;
}

/* Below the panel breakpoint: never show the panel; chips fall back to the
   existing new-tab behaviour (guarded in JS via citationPanelMinWidth). */
@media (max-width: 1279px) {
    .source-panel {
        display: none !important;
    }
    .chat-widget.source-panel-open .chat-panel {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-widget.source-panel-open .chat-panel {
        transition: none;
    }
    .source-panel-skeleton {
        animation: none;
    }
}

/* ========== Embedded surfaces (in-app Chat tab + left drawer) ========== */
/* The same chat markup powers the standalone floating widget, the full-screen
   Chat tab, and the left drawer. On the embedded surfaces the chat fills its
   host container instead of floating bottom-left, and the launcher/header are
   gone (the host provides those controls). */
.chat-surface {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
}
.chat-surface--tab #chat-widget,
.chat-surface--drawer #chat-widget {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    width: 100%;
    height: 100%;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    z-index: auto;
}
.chat-surface--tab #chat-panel,
.chat-surface--drawer #chat-panel {
    /* position:relative makes the panel the containing block for the chat's own
       absolutely-positioned overlays (session-feedback bottom-sheet, Pasta-CC /
       clarification modals). Combined with the panel's overflow:hidden, the
       session-feedback sheet (hidden via translateY(100%)) is clipped to the
       panel instead of poking out the bottom of the surface. */
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    flex: 1 1 auto;
    min-height: 0;
    box-shadow: none;
}
.chat-surface--no-header .chat-header { display: none; }
.chat-surface--tab .widget-btn,
.chat-surface--drawer .widget-btn { display: none; }

/* Tab: center the reading column like ChatGPT/Claude (mirrors .fullscreen). */
.chat-surface--tab .chat-messages,
.chat-surface--tab .chat-input-container,
.chat-surface--tab .quick-actions-container,
.chat-surface--tab .file-preview {
    --content-max-width: 900px;
    padding-left: max(var(--spacing-md), calc((100% - var(--content-max-width)) / 2));
    padding-right: max(var(--spacing-md), calc((100% - var(--content-max-width)) / 2));
}
.chat-surface--tab .message.user { max-width: 75%; }
.chat-surface--tab .welcome-message { max-width: 700px; align-self: center; }

/* ========== Chat Header ========== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--text-white);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    flex: 1;
    min-width: 0;
}

.logo {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
    text-decoration: none;
    padding: 4px;
}

.logo:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.header-info {
    flex: 1;
    min-width: 0;
}

.header-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-subtitle {
    margin: 0;
    font-size: 13px;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    gap: var(--spacing-xs);
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

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

/* ========== Chat Messages ========== */
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: var(--spacing-lg);
    background: var(--bg-gray-50);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: var(--spacing-xl) var(--spacing-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
}

.welcome-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light) 0%, #bae6fd 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: var(--primary-color);
    box-shadow: var(--shadow-lg), inset 0 -4px 12px rgba(0, 0, 0, 0.05);
    animation: float 3s ease-in-out infinite;
}

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

.welcome-title {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.welcome-text {
    margin: 0;
    font-size: 16px;
    color: var(--text-secondary);
}

/* Message Bubbles */
.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: slideIn 0.3s ease;
}

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

.message.user {
    align-self: flex-end;
}

.message.bot {
    align-self: flex-start;
}

.message-content {
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    line-height: 1.5;
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--primary-light) 0%, #bae6fd 100%);
    color: var(--text-primary);
    border-bottom-right-radius: var(--spacing-xs);
}

.message.bot .message-content {
    background: var(--bg-white);
    color: var(--text-primary);
    border-bottom-left-radius: var(--spacing-xs);
    box-shadow: var(--shadow-sm);
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: var(--spacing-xs);
    padding: 0 var(--spacing-sm);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: var(--spacing-xs);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    width: fit-content;
}

.typing-dots {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: var(--spacing-xs) 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: typingPulse 1.5s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingPulse {
    0%, 100% {
        transform: scale(0.8);
        opacity: 0.4;
    }
    50% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Thinking Indicator */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) 0;
}

.thinking-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
    transition: opacity 0.15s ease-in-out;
}

/* Streaming Cursor */
.streaming-cursor {
    display: inline-block;
    animation: blink 1s infinite;
    color: var(--primary-color);
    font-weight: bold;
}

@keyframes blink {
    0%, 49% {
        opacity: 1;
    }
    50%, 100% {
        opacity: 0;
    }
}

/* ========== Tools Used Container (Modern UI) ========== */
.tools-container {
    margin-top: var(--spacing-md);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.tools-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.08) 0%, rgba(139, 92, 246, 0.04) 100%);
    border: 1px solid rgba(139, 92, 246, 0.15);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.tools-header:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.12) 0%, rgba(139, 92, 246, 0.08) 100%);
    border-color: rgba(139, 92, 246, 0.25);
}

.tools-header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.tools-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.tools-title {
    font-size: 13px;
    font-weight: 600;
    color: #7c3aed;
}

.tools-badge {
    background: #8b5cf6;
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}

.tools-toggle {
    font-size: 12px;
    color: var(--text-secondary);
    transition: transform var(--transition-fast);
}

.tools-container.expanded .tools-toggle {
    transform: rotate(180deg);
}

.tools-list {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.tools-container.expanded .tools-list {
    max-height: 5000px;
    margin-top: var(--spacing-sm);
}

/* Individual Tool Item */
.tool-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm) var(--spacing-md);
    margin-bottom: var(--spacing-xs);
    transition: all var(--transition-fast);
}

.tool-item:last-child {
    margin-bottom: 0;
}

.tool-item:hover {
    border-color: rgba(139, 92, 246, 0.3);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.1);
}

.tool-item.error {
    border-color: rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.02);
}

.tool-item-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(139, 92, 246, 0.05) 100%);
    color: #8b5cf6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.tool-item.error .tool-item-icon {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(239, 68, 68, 0.05) 100%);
    color: #ef4444;
}

.tool-item-content {
    flex: 1;
    min-width: 0;
}

.tool-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.tool-item-query {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tool-item-result {
    font-size: 12px;
    color: #059669;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tool-item-result i {
    font-size: 10px;
}

.tool-item-result.error {
    color: #ef4444;
}

/* Expandable Tool Item Header */
.tool-item-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    width: 100%;
}

.tool-item-header.expandable {
    cursor: pointer;
}

.tool-item-header.expandable:hover {
    opacity: 0.9;
}

.tool-item-toggle {
    font-size: 10px;
    color: var(--text-secondary);
    transition: transform var(--transition-fast);
    flex-shrink: 0;
    margin-top: 0;
    margin-left: auto;
}

.tool-item.expanded .tool-item-toggle {
    transform: rotate(180deg);
}

/* Tool Item Details (Hidden by default) */
.tool-item-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
    margin-top: 0;
    border-top: 0 solid var(--border-color);
    width: 100%;
}

.tool-item.expanded .tool-item-details {
    max-height: 3000px;
    margin-top: var(--spacing-sm);
    padding-top: var(--spacing-sm);
    border-top-width: 1px;
}

/* Scrollbar for tool details */
.tool-item-details::-webkit-scrollbar {
    width: 4px;
}

.tool-item-details::-webkit-scrollbar-track {
    background: transparent;
}

.tool-item-details::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.tool-item-details::-webkit-scrollbar-thumb:hover {
    background: var(--border-color-dark);
}

/* Tool Detail Section */
.tool-detail-section {
    margin-bottom: var(--spacing-md);
}

.tool-detail-section:last-child {
    margin-bottom: 0;
}

.tool-detail-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--spacing-xs);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.tool-detail-label i {
    color: #8b5cf6;
    font-size: 10px;
}

/* Input Parameters Styling */
.tool-detail-params {
    background: var(--bg-gray-50);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm);
    border: 1px solid var(--border-color);
}

.tool-param {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-sm);
    font-size: 12px;
    padding: var(--spacing-xs) 0;
    border-bottom: 1px dashed var(--border-color);
}

.tool-param:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.tool-param:first-child {
    padding-top: 0;
}

.tool-param-key {
    font-weight: 600;
    color: #8b5cf6;
    flex-shrink: 0;
    font-family: 'Courier New', monospace;
}

.tool-param-value {
    color: var(--text-primary);
    word-break: break-word;
    flex: 1;
    min-width: 0;
    /* Preserve newlines emitted by formatParamValue for arrays/objects
       (plan sub_questions bullet list, retrieval_plan step lines, etc.) */
    white-space: pre-wrap;
}

/* Output Results Styling */
.tool-detail-results {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.tool-output-item {
    display: flex;
    gap: var(--spacing-sm);
    background: var(--bg-gray-50);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm);
    border: 1px solid var(--border-color);
}

.tool-output-item:hover {
    border-color: rgba(139, 92, 246, 0.3);
    background: rgba(139, 92, 246, 0.02);
}

.tool-output-rank {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tool-output-content {
    flex: 1;
    min-width: 0;
}

.tool-output-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    line-height: 1.3;
}

.tool-output-title-link {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.tool-output-title-link:hover {
    color: #8b5cf6;
    text-decoration: underline;
}

.tool-output-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.tool-output-type {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    background: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
    text-transform: capitalize;
}

.tool-output-score {
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 500;
}

.tool-output-preview {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Generic JSON output (for database queries etc.) */
.tool-output-item.generic {
    display: block;
}

.tool-output-json {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    max-height: 150px;
    overflow-y: auto;
}

/* News and calendar tool output styles */
.tool-output-item.news,
.tool-output-item.calendar {
    display: block;
    padding: var(--spacing-sm) var(--spacing-md);
}

.tool-output-item.news .tool-output-meta,
.tool-output-item.calendar .tool-output-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    align-items: center;
}

.tool-output-count {
    font-size: 12px;
    color: var(--occ-green);
    font-weight: 600;
}

.tool-output-period {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 2px 6px;
    background: var(--bg-gray-100);
    border-radius: var(--radius-sm);
}

.tool-output-link {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-xs);
    font-size: 11px;
    color: var(--occ-blue);
    text-decoration: none;
    transition: color 0.2s ease;
}

.tool-output-link:hover {
    color: var(--occ-green);
    text-decoration: underline;
}

.tool-output-link i {
    font-size: 10px;
}

/* Dark mode adjustments for tool details */
.dark-mode .tool-detail-params {
    background: var(--bg-gray-100);
    border-color: var(--border-color);
}

.dark-mode .tool-output-item {
    background: var(--bg-gray-100);
    border-color: var(--border-color);
}

.dark-mode .tool-output-item:hover {
    background: rgba(139, 92, 246, 0.08);
}

.dark-mode .tool-param-value {
    color: var(--text-primary);
}

.dark-mode .tool-output-title {
    color: var(--text-primary);
}

.dark-mode .tool-output-period {
    background: var(--bg-gray-200);
}

.dark-mode .tool-output-link {
    color: #3498db;
}

.dark-mode .tool-output-link:hover {
    color: var(--occ-green);
}

/* ========== Retrieved Sources Cards (Modern UI) ========== */
.sources-container {
    margin-top: var(--spacing-md);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.sources-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: linear-gradient(135deg, rgba(0, 131, 142, 0.08) 0%, rgba(0, 131, 142, 0.04) 100%);
    border: 1px solid rgba(0, 131, 142, 0.15);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.sources-header:hover {
    background: linear-gradient(135deg, rgba(0, 131, 142, 0.12) 0%, rgba(0, 131, 142, 0.08) 100%);
    border-color: rgba(0, 131, 142, 0.25);
}

.sources-header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.sources-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.sources-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-dark);
}

.sources-badge {
    background: var(--primary-color);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}

.sources-toggle {
    font-size: 12px;
    color: var(--text-secondary);
    transition: transform var(--transition-fast);
}

.sources-container.expanded .sources-toggle {
    transform: rotate(180deg);
}

.sources-list {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.sources-container.expanded .sources-list {
    max-height: 5000px;
    margin-top: var(--spacing-sm);
}

/* Individual Source Card */
.source-card {
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.source-card:last-child {
    margin-bottom: 0;
}

.source-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 131, 142, 0.1);
    transform: translateY(-1px);
}

.source-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.source-card-info {
    flex: 1;
    min-width: 0;
}

.source-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.source-card-title-link {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

.source-card-title-link:hover {
    color: var(--primary-color-dark, #006670);
    text-decoration: underline;
}

.source-external-link {
    display: inline-flex;
    align-items: center;
    color: var(--primary-color);
    font-size: 10px;
    opacity: 0.8;
}

.source-external-link i {
    font-size: 10px;
}

.source-card-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.source-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg-gray-100);
    color: var(--text-secondary);
    text-transform: capitalize;
}

.source-type-badge i {
    font-size: 10px;
}

/* Score Badge with Color Coding */
.source-score {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.source-score i {
    font-size: 10px;
}

/* Score color variants */
.source-score.score-excellent {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    color: #166534;
    border: 1px solid #86efac;
}

.source-score.score-good {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.source-score.score-moderate {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
    border: 1px solid #fcd34d;
}

.source-score.score-low {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #991b1b;
    border: 1px solid #fca5a5;
}

/* Source Text Preview */
.source-card-text {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
    background: var(--bg-gray-50);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary-color);
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Relevance Bar (visual indicator) */
.source-relevance-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 3px;
    border-radius: 0 0 var(--radius-sm) 0;
    transition: width var(--transition-normal);
}

.source-relevance-bar.excellent {
    background: linear-gradient(90deg, #22c55e 0%, #4ade80 100%);
}

.source-relevance-bar.good {
    background: linear-gradient(90deg, #3b82f6 0%, #60a5fa 100%);
}

.source-relevance-bar.moderate {
    background: linear-gradient(90deg, #f59e0b 0%, #fbbf24 100%);
}

.source-relevance-bar.low {
    background: linear-gradient(90deg, #ef4444 0%, #f87171 100%);
}

/* Source rank indicator */
.source-rank {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-gray-100);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.source-rank.rank-1 {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
}

.source-rank.rank-2 {
    background: linear-gradient(135deg, #e5e7eb 0%, #d1d5db 100%);
    color: #4b5563;
}

.source-rank.rank-3 {
    background: linear-gradient(135deg, #fed7aa 0%, #fdba74 100%);
    color: #9a3412;
}

/* Dark mode adjustments */
.dark-mode .sources-header {
    background: linear-gradient(135deg, rgba(0, 131, 142, 0.15) 0%, rgba(0, 131, 142, 0.08) 100%);
    border-color: rgba(0, 131, 142, 0.3);
}

.dark-mode .sources-title {
    color: #67e8f9;
}

.dark-mode .source-card {
    background: var(--bg-gray-50);
    border-color: var(--border-color);
}

.dark-mode .source-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 131, 142, 0.2);
}

.dark-mode .source-card-title {
    color: var(--text-primary);
}

.dark-mode .source-card-title-link {
    color: var(--primary-color-light, #4dd0e1);
}

.dark-mode .source-card-title-link:hover {
    color: var(--primary-color);
}

.dark-mode .source-external-link {
    color: var(--primary-color-light, #4dd0e1);
}

.dark-mode .source-card-text {
    background: var(--bg-gray-100);
    color: var(--text-secondary);
}

/* Legacy sources card (backwards compatibility) */
.sources-card {
    background: var(--bg-gray-50);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--primary-color);
    padding: var(--spacing-md);
    margin-top: var(--spacing-sm);
    font-size: 14px;
}

.sources-card strong {
    color: var(--primary-color);
    display: block;
    margin-bottom: var(--spacing-sm);
}

.sources-card ul {
    margin: 0;
    padding-left: var(--spacing-lg);
}

.sources-card li {
    margin-bottom: var(--spacing-xs);
}

.source-link {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.source-link:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* ========== Quick Actions ========== */
.quick-actions-container {
    padding: var(--spacing-md) var(--spacing-md) 0 var(--spacing-md);
    background: var(--bg-white);
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    justify-content: center;
    margin-bottom: var(--spacing-sm);
}

.quick-action-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background: linear-gradient(135deg, rgba(0, 131, 142, 0.08) 0%, rgba(0, 131, 142, 0.12) 100%);
    border: 1px solid rgba(0, 131, 142, 0.2);
    border-radius: 20px;
    color: var(--primary-color);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.quick-action-btn i {
    font-size: 14px;
    opacity: 0.9;
}

.quick-action-btn:hover {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--text-white);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 131, 142, 0.25);
}

.quick-action-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 131, 142, 0.15);
}

/* Hide quick actions when messages are present */
.has-messages .quick-actions-container {
    display: none;
}

/* ========== Chat Input ========== */
.chat-input-container {
    padding: var(--spacing-md);
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-sm);
}

.input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    background: var(--bg-gray-100);
    border-radius: var(--radius-md);
    padding: 0 var(--spacing-md);
    border: 2px solid transparent;
    transition: all var(--transition-fast);
}

.input-wrapper:focus-within {
    background: var(--bg-white);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 131, 142, 0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: var(--spacing-md) 0;
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
    resize: none;
    overflow-y: hidden;
    max-height: 120px;
    line-height: 1.4;
    font-family: inherit;
}

.chat-input::placeholder {
    color: var(--text-secondary);
}

.input-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all var(--transition-fast);
}

.input-icon-btn:hover {
    color: var(--primary-color);
    background: rgba(0, 131, 142, 0.1);
}

.input-icon-btn.recording {
    color: var(--error-color);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.send-btn {
    padding: 0 var(--spacing-lg);
    height: 44px;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--text-white);
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.send-btn:active {
    transform: translateY(0);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========== Sidebar (Settings Overlay) ========== */
.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-white);
    box-shadow: var(--shadow-lg);
    z-index: 10000; /* Above widget */
    overflow-y: auto;
    transition: left var(--transition-normal);
}

.sidebar.open {
    left: 0;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999; /* Below sidebar, above widget */
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.sidebar-overlay.active {
    opacity: 1;
}

.sidebar-header {
    padding: var(--spacing-lg);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--text-white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.sidebar-content {
    padding: var(--spacing-lg);
}

/* Sidebar Sections */
.sidebar-section {
    margin-bottom: var(--spacing-xl);
}

.sidebar-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--spacing-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.sidebar-btn {
    width: 100%;
    background: var(--bg-gray-100);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--spacing-md);
    font-size: 14px;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    transition: all var(--transition-fast);
    margin-bottom: var(--spacing-sm);
}

a.sidebar-btn {
    text-decoration: none;
    color: var(--text-primary);
}

.sidebar-btn:hover {
    background: var(--bg-gray-200);
    border-color: var(--border-color-dark);
}

.sidebar-btn.primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--text-white);
    border-color: var(--primary-color);
}

.sidebar-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.sidebar-btn.active {
    background: linear-gradient(135deg, var(--success-color) 0%, var(--success-dark) 100%);
    color: var(--text-white);
    border-color: var(--success-color);
}

/* Account section (signed-in user info + logout) */
.account-info {
    padding: var(--spacing-sm) var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    /* --bg-gray-50 has a dark-mode override (line 65); using it keeps the
       account box visually consistent with other inset panels in both
       themes. Avoid `var(--bg-light)` — that token isn't defined and the
       fallback would freeze the box to a light shade under dark mode. */
    background: var(--bg-gray-50);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}
.account-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.account-email {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* FAQ Accordion */
.faq-item {
    margin-bottom: var(--spacing-sm);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.faq-toggle {
    width: 100%;
    background: var(--bg-white);
    border: none;
    padding: var(--spacing-md);
    font-size: 14px;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background var(--transition-fast);
}

.faq-toggle:hover {
    background: var(--bg-gray-50);
}

.faq-toggle i {
    transition: transform var(--transition-fast);
}

.faq-toggle.active i {
    transform: rotate(180deg);
}

.faq-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-normal);
}

.faq-content.active {
    max-height: 500px;
}

.faq-text {
    padding: 0 var(--spacing-md) var(--spacing-md);
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Tips Box */
.tip-box {
    background: linear-gradient(135deg, var(--primary-light) 0%, #bae6fd 100%);
    border-left: 4px solid var(--primary-color);
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
    display: flex;
    gap: var(--spacing-md);
}

.tip-icon {
    color: var(--primary-color);
    font-size: 20px;
    flex-shrink: 0;
}

.tip-content {
    flex: 1;
}

.tip-title {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: var(--spacing-xs);
    font-size: 14px;
}

.tip-text {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.5;
    margin: 0;
}

/* ========== Responsive Design ========== */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
    }

    .chat-panel {
        width: 100vw;
        height: 100vh;
        height: 100dvh;   /* dvh pair — same convention as shell.css */
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .quick-action-btn { white-space: normal; }

    .widget-btn {
        bottom: var(--spacing-md);
        right: var(--spacing-md);
    }

    .message {
        max-width: 90%;
    }

    .sidebar {
        width: 240px;
        left: -240px;
    }

    .sidebar.open {
        left: 0;
    }

    .header-title {
        font-size: 16px;
    }

    .header-subtitle {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    :root {
        --spacing-md: 12px;
        --spacing-lg: 16px;
    }

    .chat-input-container {
        flex-direction: column;
    }

    .send-btn {
        width: 100%;
        justify-content: center;
        padding: var(--spacing-md);
    }

    .sidebar {
        width: 100vw;
        left: -100vw;
    }

    .sidebar.open {
        left: 0;
    }
}

/* ========== Markdown Content Styling ========== */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin-top: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    font-weight: 600;
    line-height: 1.4;
}

.message-content h1 {
    font-size: 20px;
}

.message-content h2 {
    font-size: 18px;
}

.message-content h3 {
    font-size: 16px;
    background: linear-gradient(135deg, rgba(0, 131, 142, 0.12) 0%, rgba(0, 131, 142, 0.08) 100%);
    color: var(--primary-dark);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--primary-color);
}

.message-content h4 {
    font-size: 15px;
    background: linear-gradient(135deg, rgba(0, 131, 142, 0.08) 0%, rgba(0, 131, 142, 0.04) 100%);
    color: var(--primary-dark);
    border-left: 3px solid var(--primary-color);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
}

.message-content h5 {
    font-size: 14px;
}

.message-content h6 {
    font-size: 13px;
}

.message-content p {
    margin: var(--spacing-sm) 0;
}

.message-content ul,
.message-content ol {
    padding-left: var(--spacing-lg);
    margin: var(--spacing-sm) 0;
}

.message-content li {
    margin-bottom: var(--spacing-xs);
}

.message-content code {
    background: var(--bg-gray-100);
    padding: 2px 6px;
    border-radius: var(--spacing-xs);
    font-size: 13px;
}

.message-content pre {
    background: var(--bg-gray-100);
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
    overflow-x: auto;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: var(--spacing-lg) 0;
}

.message-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

/* Enhanced markdown elements */
.message-content blockquote {
    border-left: 4px solid var(--primary-color);
    background: var(--primary-light);
    padding: var(--spacing-sm) var(--spacing-md);
    margin: var(--spacing-md) 0;
    border-radius: var(--radius-sm);
    font-style: italic;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--spacing-md) 0;
    font-size: 14px;
    border-radius: var(--radius-sm);
    /* Wide tables pan inside the bubble instead of overflowing it — same
       pattern as document_detail.html's .dd-canvas table. */
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.message-content th,
.message-content td {
    padding: var(--spacing-sm) var(--spacing-md);
    text-align: left;
    border: 1px solid var(--border-color);
}

.message-content th {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

.message-content tr:nth-child(even) {
    background: var(--bg-gray-50);
}

.message-content tr:hover {
    background: var(--primary-light);
}

/* Code blocks with syntax highlighting */
.message-content pre {
    position: relative;
    background: var(--bg-gray-100);
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    border: 1px solid var(--border-color);
    margin: var(--spacing-md) 0;
}

.message-content pre code {
    background: none;
    padding: 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    line-height: 1.5;
}

/* Inline code */
.message-content code {
    background: var(--bg-gray-100);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Courier New', Courier, monospace;
    border: 1px solid var(--border-color);
}

/* Task lists */
.message-content input[type="checkbox"] {
    margin-right: var(--spacing-xs);
}

/* Strong and emphasis */
.message-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-content em {
    font-style: italic;
}

/* Horizontal rules */
.message-content hr {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: var(--spacing-lg) 0;
}

/* ========== File Upload Styles ========== */

/* File Preview Bar */
.file-preview {
    background: var(--bg-gray-100);
    border-top: 1px solid var(--border-color);
    padding: var(--spacing-sm) var(--spacing-md);
    display: flex;
    align-items: stretch;
}

.file-preview-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    flex: 1;
    min-width: 0;
    max-height: 132px;
    overflow-y: auto;
}

.file-preview-content {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    background: var(--bg-white);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    max-width: 100%;
}

.file-icon {
    font-size: 20px;
    color: var(--primary-color);
    flex-shrink: 0;
}

.file-icon.fa-file-pdf {
    color: #dc3545;
}

.file-icon.fa-file-word {
    color: #2b579a;
}

.file-name {
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.remove-file-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.remove-file-btn:hover {
    background: var(--error-color);
    color: var(--text-white);
}

/* File Error Toast */
.file-error-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--error-color);
    color: var(--text-white);
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 14px;
    z-index: 10001;
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 90%;
    text-align: center;
}

.file-error-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.file-error-toast i {
    font-size: 18px;
    flex-shrink: 0;
}

/* Paperclip button styling */
.input-icon-btn[id="file-btn"] {
    color: var(--text-secondary);
}

.input-icon-btn[id="file-btn"]:hover {
    color: var(--primary-color);
    background: rgba(0, 131, 142, 0.1);
}

/* Dark mode adjustments for file upload */
.dark-mode .file-preview {
    background: var(--bg-gray-100);
}

.dark-mode .file-preview-content {
    background: var(--bg-gray-50);
    border-color: var(--border-color);
}

.dark-mode .file-name {
    color: var(--text-primary);
}

.dark-mode .remove-file-btn {
    color: var(--text-secondary);
}

.dark-mode .remove-file-btn:hover {
    background: var(--error-color);
    color: var(--text-white);
}

/* ========== Feedback Styles ========== */

/* Per-turn feedback actions */
.feedback-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
    padding-top: var(--spacing-sm);
    opacity: 0;
    animation: feedbackFadeIn 0.4s ease forwards;
    animation-delay: 0.3s;
}

@keyframes feedbackFadeIn {
    to { opacity: 1; }
}

.feedback-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: all var(--transition-fast);
}

.feedback-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(0, 131, 142, 0.08);
}

.feedback-btn.active-positive {
    border-color: var(--success-color);
    color: var(--text-white);
    background: var(--success-color);
}

.feedback-btn.active-negative {
    border-color: #e67e22;
    color: var(--text-white);
    background: #e67e22;
}

.feedback-btn.dimmed {
    opacity: 0.3;
}

/* Feedback expanded area */
.feedback-expanded {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease;
    margin-top: 0;
}

/* Pasta CC reformat — pill button in the feedback row */
.pastacc-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    font-family: inherit;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.pastacc-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(0, 131, 142, 0.08);
}

.pastacc-btn i {
    font-size: 12px;
}

/* Pasta CC reformat — modal */
.pastacc-overlay {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.pastacc-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.pastacc-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 520px;
    max-height: 85%;
    background: var(--bg-white);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.pastacc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.pastacc-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.pastacc-title i {
    color: var(--primary-color);
}

.pastacc-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all var(--transition-fast);
}

.pastacc-close:hover {
    background: var(--bg-gray-100);
    color: var(--text-primary);
}

.pastacc-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-lg);
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
}

.pastacc-body.loading {
    color: var(--text-secondary);
    font-style: italic;
}

.pastacc-footer {
    display: flex;
    justify-content: flex-end;
    padding: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid var(--border-color);
}

.pastacc-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    border-radius: 14px;
    background: var(--primary-color);
    color: var(--text-white);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.pastacc-copy-btn:hover:not(:disabled) {
    background: var(--primary-dark);
}

.pastacc-copy-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pastacc-copy-btn.copied {
    background: var(--success-color);
}

.dark-mode .pastacc-card {
    background: var(--bg-gray-50);
}

/* Clarification — reopen button on the clarification bubble */
.clarify-bubble-actions {
    margin-top: var(--spacing-sm);
}

.clarify-reopen-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid var(--primary-color);
    border-radius: 14px;
    background: rgba(0, 131, 142, 0.08);
    color: var(--primary-color);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.clarify-reopen-btn:hover:not(:disabled) {
    background: var(--primary-color);
    color: var(--text-white);
}

.clarify-reopen-btn:disabled {
    border-color: var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    cursor: default;
}

/* Clarification — modal */
.clarify-overlay {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.clarify-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.clarify-modal-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 520px;
    max-height: 85%;
    background: var(--bg-white);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.clarify-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.clarify-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.clarify-title i {
    color: var(--primary-color);
}

.clarify-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all var(--transition-fast);
}

.clarify-close:hover {
    background: var(--bg-gray-100);
    color: var(--text-primary);
}

.clarify-intro {
    margin: 0;
    padding: var(--spacing-md) var(--spacing-lg) 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.clarify-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md) var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.clarify-card {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.clarify-question {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.5;
}

.clarify-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
}

.clarify-chip {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 11px;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.clarify-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.clarify-chip.selected {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: var(--text-white);
}

.clarify-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    box-sizing: border-box;
}

.clarify-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.clarify-footer {
    display: flex;
    justify-content: flex-end;
    padding: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid var(--border-color);
}

.clarify-submit-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: 14px;
    background: var(--primary-color);
    color: var(--text-white);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.clarify-submit-btn:hover {
    background: var(--primary-dark);
}

.dark-mode .clarify-modal-card {
    background: var(--bg-gray-50);
}

.dark-mode .clarify-input {
    background: var(--bg-gray-100);
}

/* Toast notifications */
.widget-toast {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(-12px);
    z-index: 300;
    max-width: 80%;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    background: var(--text-primary);
    color: var(--text-white);
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.widget-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.widget-toast-success {
    background: var(--success-color);
}

.widget-toast-error {
    background: var(--error-color);
}

.widget-toast-info {
    background: var(--primary-color);
}

.feedback-expanded.open {
    max-height: 300px;
    margin-top: var(--spacing-sm);
}

.feedback-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: var(--spacing-sm);
}

.feedback-chip {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-gray-50);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.feedback-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.feedback-chip.selected {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: var(--text-white);
}

.feedback-comment {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    resize: vertical;
    min-height: 40px;
    max-height: 100px;
    outline: none;
    transition: border-color var(--transition-fast);
}

.feedback-comment:focus {
    border-color: var(--primary-color);
}

.feedback-comment::placeholder {
    color: var(--text-secondary);
}

.feedback-submit-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    margin-top: 6px;
    border: none;
    border-radius: 14px;
    background: var(--primary-color);
    color: var(--text-white);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.feedback-submit-btn:hover {
    background: var(--primary-dark);
}

.feedback-confirmation {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--success-color);
    font-size: 12px;
    font-weight: 500;
    animation: feedbackFadeIn 0.3s ease forwards;
}

.feedback-confirmation i {
    font-size: 14px;
}

/* Session feedback overlay */
.session-feedback-overlay {
    /* Hidden for real (not just translated off-panel): in the tab surface the
       panel does not clip, so the sheet used to sit below the composer on load. */
    visibility: hidden;
    pointer-events: none;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    pointer-events: none;
}

.session-feedback-overlay.visible {
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
    pointer-events: auto;
}

.session-feedback-card {
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    padding: var(--spacing-lg);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.1);
}

.session-feedback-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.session-feedback-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.session-feedback-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all var(--transition-fast);
}

.session-feedback-close:hover {
    background: var(--bg-gray-100);
    color: var(--text-primary);
}

.emoji-rating {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: var(--spacing-md);
}

.emoji-rating button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-gray-50);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.emoji-rating button:hover {
    border-color: var(--primary-color);
    transform: scale(1.1);
}

.emoji-rating button.selected {
    border-color: var(--primary-color);
    background: var(--primary-light);
    transform: scale(1.15);
}

.emoji-rating button.dimmed {
    opacity: 0.3;
    transform: scale(0.95);
}

.session-feedback-categories {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: var(--spacing-sm);
}

.session-feedback-categories.visible {
    display: flex;
    animation: feedbackFadeIn 0.3s ease forwards;
}

.session-feedback-chip {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-gray-50);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.session-feedback-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.session-feedback-chip.selected {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: var(--text-white);
}

.session-feedback-comment {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    resize: none;
    min-height: 50px;
    outline: none;
    margin-bottom: var(--spacing-sm);
    transition: border-color var(--transition-fast);
    display: none;
}

.session-feedback-comment.visible {
    display: block;
    animation: feedbackFadeIn 0.3s ease forwards;
}

.session-feedback-comment:focus {
    border-color: var(--primary-color);
}

.session-feedback-submit {
    display: none;
    width: 100%;
    padding: 8px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary-color);
    color: var(--text-white);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.session-feedback-submit.visible {
    display: block;
    animation: feedbackFadeIn 0.3s ease forwards;
}

.session-feedback-submit:hover {
    background: var(--primary-dark);
}

.session-feedback-confirmation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    color: var(--success-color);
    font-size: 15px;
    font-weight: 500;
}

/* Dark mode feedback overrides */
.dark-mode .feedback-btn {
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.dark-mode .feedback-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(0, 131, 142, 0.15);
}

.dark-mode .feedback-chip {
    background: var(--bg-gray-100);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.dark-mode .feedback-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.dark-mode .feedback-chip.selected {
    background: var(--primary-color);
    color: var(--text-white);
}

.dark-mode .feedback-comment {
    background: var(--bg-gray-50);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.dark-mode .session-feedback-card {
    background: var(--bg-gray-50);
    border-top-color: var(--border-color);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}

.dark-mode .session-feedback-comment {
    background: var(--bg-gray-100);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.dark-mode .session-feedback-chip {
    background: var(--bg-gray-100);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.dark-mode .session-feedback-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.dark-mode .session-feedback-chip.selected {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: var(--text-white);
}

.dark-mode .emoji-rating button {
    background: var(--bg-gray-100);
    border-color: var(--border-color);
}

.dark-mode .emoji-rating button.selected {
    background: rgba(0, 131, 142, 0.3);
    border-color: var(--primary-color);
}

/* Session feedback button in header */
#session-feedback-btn {
    position: relative;
}

/* ========== Print Styles ========== */
@media print {
    .chat-header,
    .chat-input-container,
    .widget-btn,
    .file-preview,
    .overlay {
        display: none !important;
    }

    .chat-panel {
        box-shadow: none;
        border: 1px solid var(--border-color);
    }
}

/* ========== Verifier Note (Phase 1) ==========
   Rendered beneath a bot answer when the post-agent verification pass flags
   an issue (status WARN or REJECT). The note is a sibling of .message-content
   inside the .message.bot container — visually separate from the answer but
   not alarming. Annotation text arrives from the backend as plain text. */
.verifier-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    border-left: 3px solid #d97706;
    background: #fff8e1;
    color: #664400;
    font-size: 0.88em;
    line-height: 1.4;
}

.verifier-note--reject {
    border-left-color: #b91c1c;
    background: #fdecea;
    color: #7a1c1c;
}

.verifier-note-icon {
    font-size: 1.1em;
    line-height: 1;
    flex-shrink: 0;
    padding-top: 1px;
}

.verifier-note-body {
    flex: 1 1 auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ========== Two-Phase Refinement UX ==========
   Surface the verifier + optional refinement pass as a quiet pill beneath
   the answer bubble. The pill fades in on VERIFICATION_STARTED, updates
   its label on REFINEMENT_STARTED, and transitions to a ✓ Refinado
   affordance (then fades) on REFINEMENT_DONE. The bubble's content opacity
   dims while refinement is in flight so the user knows something better
   is arriving. Designed to be noticeable but never obstructive. */
.review-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 6px 12px;
    font-size: 0.85em;
    font-weight: 500;
    color: #334155;
    background: #e2e8f0;
    border-radius: 999px;
    line-height: 1.3;
    opacity: 0;
    animation: reviewPillFadeIn var(--transition-normal) ease-out forwards;
    transition: background-color var(--transition-normal) ease-out,
                color var(--transition-normal) ease-out,
                opacity var(--transition-normal) ease-out;
}

/* Accepted-refinement terminal state: green confirmation ("✓ Resposta refinada"). */
.review-pill--done {
    color: #166534;
    background: #dcfce7;
}

/* Verifier-passed terminal state: neutral confirmation ("✓ Resposta verificada").
   Shown when the verifier flagged issues but the refinement didn't produce a
   meaningfully better answer (length-regression rejection), OR when the
   verifier returned OK. Uses a softer blue-green so the user still perceives
   success without implying the content actually changed. */
.review-pill--verified {
    color: #0369a1;
    background: #e0f2fe;
}

.review-pill--fading {
    /* Clear the fade-in animation's `forwards` fill so the transition
       below is actually observable — without `animation: none`, Safari
       keeps the animation-fill lock on opacity:1 and the fade-out is
       invisible even though the transition technically runs. */
    animation: none;
    opacity: 0;
    transition: opacity var(--transition-normal) ease-out;
}

.review-pill-spinner {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgba(51, 65, 85, 0.25);
    border-top-color: #334155;
    animation: reviewPillSpin 0.9s linear infinite;
    flex-shrink: 0;
}

.review-pill-check {
    /* Drop the spinner's circular geometry when we swap to a checkmark
       glyph. Uses currentColor so it inherits whichever state class is
       active (--done green or --verified blue). */
    width: auto;
    height: auto;
    border: none;
    animation: none;
    font-size: 1em;
    line-height: 1;
    color: inherit;
    flex-shrink: 0;
}

.review-pill-label {
    /* Explicit values rather than leaning on cascade — protects against
       embedding hosts that aggressively reset span styles (Shadow DOM
       encapsulation, iframe style isolation, CSS resets like
       `* { color: inherit }` that short-circuit inheritance from
       .review-pill). The spinner survives those cascade failures because
       it sets its color on `border-top-color` directly; the label had no
       such fallback and rendered invisibly. */
    color: #334155;
    font-size: 0.85em;
    font-weight: 500;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

/* Terminal-state label color overrides. The parent `.review-pill--done`
   / `.review-pill--verified` already sets the pill's `color`; these
   selectors repeat the value on the label directly so it survives the
   same cascade failures the base rule defends against. */
.review-pill--done .review-pill-label {
    color: #166534;
}

.review-pill--verified .review-pill-label {
    color: #0369a1;
}

/* ========== Review state (verification / refinement in flight) ==========
   While the verifier and the optional refinement pass run, the answer stays
   fully legible and the bubble gets a "being checked" treatment instead of
   a grey-out: a soft ring in the brand colour that breathes, and a thin
   translucent band of light that sweeps down the bubble like a scanner.
   Everything is painted on pseudo-elements with pointer-events off, so the
   text remains selectable and links clickable. */
.message-content--reviewing {
    position: relative;
    overflow: hidden;
    animation: reviewRingBreathe 2.4s ease-in-out infinite;
}

.message-content--reviewing::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: inherit;
    background: linear-gradient(
        180deg,
        rgba(0, 131, 142, 0) 0%,
        rgba(0, 131, 142, 0.05) 40%,
        rgba(0, 131, 142, 0.14) 50%,
        rgba(0, 131, 142, 0.05) 60%,
        rgba(0, 131, 142, 0) 100%
    );
    background-size: 100% 220px;
    background-repeat: no-repeat;
    animation: reviewScanSweep 2.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.message-content--reviewing::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: inherit;
    box-shadow: inset 0 0 0 1px rgba(0, 131, 142, 0.28);
}

.dark-mode .message-content--reviewing::before {
    background-image: linear-gradient(
        180deg,
        rgba(103, 232, 249, 0) 0%,
        rgba(103, 232, 249, 0.05) 40%,
        rgba(103, 232, 249, 0.14) 50%,
        rgba(103, 232, 249, 0.05) 60%,
        rgba(103, 232, 249, 0) 100%
    );
}

.dark-mode .message-content--reviewing::after {
    box-shadow: inset 0 0 0 1px rgba(103, 232, 249, 0.3);
}

/* Accepted refinement: the swapped-in answer settles with a brief brand
   tint that fades out (class removed on animationend). */
.message-content--refreshed {
    animation: reviewRefreshedSettle 0.9s ease-out 1;
}

@keyframes reviewScanSweep {
    0%   { background-position: 0 -220px; }
    100% { background-position: 0 calc(100% + 220px); }
}

@keyframes reviewRingBreathe {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0, 131, 142, 0), var(--shadow-sm); }
    50%      { box-shadow: 0 0 0 4px rgba(0, 131, 142, 0.16), var(--shadow-sm); }
}

@keyframes reviewRefreshedSettle {
    0%   { background-color: rgba(0, 131, 142, 0.14); }
    100% { background-color: transparent; }
}

@media (prefers-reduced-motion: reduce) {
    .message-content--reviewing,
    .message-content--reviewing::before,
    .message-content--refreshed {
        animation: none;
    }
    .message-content--reviewing::before {
        background: rgba(0, 131, 142, 0.05);
    }
}

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

@keyframes reviewPillSpin {
    to { transform: rotate(360deg); }
}

/* ========== Inline Thinking Indicator (mid-answer tool call) ==========
   Rendered as a sibling of .message-content inside the bot message when a
   THINKING event arrives AFTER content has started streaming. Signals that
   the agent paused mid-answer to call a tool (lookup_codigo, calculate,
   search_documents, etc.). Deliberately muted so it doesn't interrupt the
   reading flow. Cleared on THINKING_DONE. */
.inline-thinking-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 4px 2px;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--text-secondary);
    opacity: 0.85;
}

.inline-thinking-dots {
    display: inline-block;
    letter-spacing: 2px;
    animation: inline-thinking-pulse 1.2s ease-in-out infinite;
    color: var(--primary-color);
}

.inline-thinking-label {
    font-style: italic;
}

@keyframes inline-thinking-pulse {
    0%, 100% {
        opacity: 0.4;
    }
    50% {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .inline-thinking-dots {
        animation: none;
        opacity: 0.7;
    }
}

/* ========== Agent Plan (Phase A) ==========
   Rendered ABOVE .message-content as a collapsible <details> element, so
   the user sees what the agent intends to do before the answer streams.
   Closed by default to keep the bubble readable; expands on click. */
.agent-plan {
    margin: 0 0 10px 0;
    padding: 8px 10px;
    border-radius: 6px;
    border-left: 3px solid var(--primary-color, #3b82f6);
    background: rgba(59, 130, 246, 0.06);
    font-size: 0.86em;
    line-height: 1.4;
    color: var(--text-secondary, #555);
}

.agent-plan-summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}

.agent-plan-summary::-webkit-details-marker {
    display: none;
}

.agent-plan-icon {
    display: inline-block;
    transition: transform 0.15s ease-in-out;
    color: var(--primary-color, #3b82f6);
    font-size: 0.9em;
}

details[open] > .agent-plan-summary .agent-plan-icon {
    transform: rotate(90deg);
}

.agent-plan-label {
    font-weight: 500;
    color: var(--text-primary, #222);
}

.agent-plan-body {
    margin-top: 8px;
    padding-left: 4px;
}

.agent-plan-section-title {
    margin-top: 8px;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 0.88em;
    color: var(--text-primary, #222);
}

.agent-plan-list {
    margin: 0;
    padding-left: 20px;
}

.agent-plan-list li {
    margin-bottom: 3px;
}

.agent-plan-tool {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
    font-size: 0.9em;
    background: rgba(0, 0, 0, 0.05);
    padding: 1px 5px;
    border-radius: 3px;
}

.agent-plan-why {
    color: var(--text-secondary, #555);
    font-style: italic;
}

.agent-plan-shape {
    color: var(--text-secondary, #555);
    font-style: italic;
    padding-left: 4px;
}

@media (prefers-reduced-motion: reduce) {
    .agent-plan-icon {
        transition: none;
    }
}

/* ========== Agent Reasoning (per-tool thinking trace) ==========
   One blockquote per intermediate ReAct iteration, stacked inside a
   container placed between the plan block and .message-content. Muted
   palette, consistent across tools — the tool is identified only by
   icon + label, not by colour (keeps the bubble readable when several
   iterations fire). */
.agent-reasoning-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 0 10px 0;
}

.agent-reasoning {
    margin: 0;
    padding: 6px 10px;
    border-left: 3px solid var(--border-color);
    background: transparent;
    font-size: 0.88em;
    line-height: 1.45;
    color: var(--text-secondary);
    font-style: italic;
}

.agent-reasoning__label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
    font-size: 0.82em;
    font-style: normal;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
    opacity: 0.9;
}

.agent-reasoning__label i {
    font-size: 0.9em;
    opacity: 0.85;
}

.agent-reasoning__text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ========== Finish Badges (Phase C) ==========
   Small pills surfacing agent-reported confidence and review status from
   the finish() tool call. Rendered below the answer body; silent when
   the agent reported high confidence + no review flag (most cases). */
.finish-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.finish-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    line-height: 1.4;
    font-weight: 500;
}

.finish-badge-icon {
    font-size: 0.85em;
    line-height: 1;
}

.finish-badge--review {
    background: #fff8e1;
    color: #8a6100;
    border: 1px solid #f0c36d;
}

.finish-badge--confidence-medium {
    background: #f3f4f6;
    color: #555;
    border: 1px solid #d1d5db;
}

.finish-badge--confidence-low {
    background: #fef3f2;
    color: #7a1c1c;
    border: 1px solid #f3a8a8;
}

/* Restricted (PastaCC) placeholder — muted, non-interactive */
.source-card-restricted {
    opacity: 0.65;
    pointer-events: none;
    background: var(--surface-muted, #f4f6f7);
}
.source-card-restricted .source-card-title { color: var(--text-muted, #6b7a80); }
.source-card-restricted .fa-lock { margin-right: 6px; font-size: 12px; }

/* ========== Mobile touch targets ========== */
/* Kept at the end of the file: these must out-cascade the base button rules
   above (equal specificity — source order decides). Spec: mobile hit areas
   >= 44px. */
@media (max-width: 768px) {
    .feedback-btn,
    .icon-btn,
    .input-icon-btn {
        width: 44px;
        height: 44px;
    }
}

/* PII mask tokens (<person_name_8932>) rendered as pills — see js/pii-tokens fence */
.pii-token {
    display: inline-block;
    padding: 0 7px;
    border-radius: 999px;
    background: #f1f3f5;
    color: #5f6b7a;
    font-size: 0.85em;
    font-style: italic;
    border: 1px dashed #c8ced6;
    line-height: 1.5;
    white-space: nowrap;
}


/* ========== Answer callouts (verifier / corrector addenda) ========== */
.answer-callout {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin: 14px 0 4px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid;
    font-size: 0.93em;
    line-height: 1.5;
}
.answer-callout--warning { background: #fff8e6; border-color: #f2d48a; color: #6b4f00; }
.answer-callout--info { background: #eef5fb; border-color: #bfd7ec; color: #1f4b6e; }
.answer-callout--tip { background: #eef8ef; border-color: #bfe0c3; color: #235c2e; }
.answer-callout-icon { flex: 0 0 auto; line-height: 1.5; }
.answer-callout-body { flex: 1 1 auto; min-width: 0; }
.dark-mode .answer-callout--warning { background: #3a3013; border-color: #6b5a1f; color: #f2d48a; }
.dark-mode .answer-callout--info { background: #16283a; border-color: #2c4a66; color: #bfd7ec; }
.dark-mode .answer-callout--tip { background: #163121; border-color: #2c5a3a; color: #bfe0c3; }

/* ========== Reading column in the tab surface (2026-08-30) ========== */
/* Bot answers get the full column; only the member's own bubbles stay narrow. */
.chat-surface--tab .chat-messages,
.chat-surface--tab .chat-input-container,
.chat-surface--tab .quick-actions-container,
.chat-surface--tab .file-preview,
.chat-widget.fullscreen .chat-messages {
    --content-max-width: 980px;
}
.chat-surface--tab .message.bot,
.chat-surface--tab .message.assistant,
.chat-widget.fullscreen .message.bot { max-width: 100%; }

/* Quick actions stay available (compact) once the conversation has started. */
.has-messages .quick-actions-container {
    display: block;
    padding-top: 4px;
    padding-bottom: 0;
}
.has-messages .quick-actions { margin-bottom: 4px; justify-content: flex-start; }
.has-messages .quick-action-btn { padding: 4px 10px; font-size: 0.8em; opacity: 0.85; }
.has-messages .quick-action-btn:hover { opacity: 1; }

.thinking-elapsed { margin-left: 8px; font-size: 0.85em; color: var(--text-muted, #7a8290); font-variant-numeric: tabular-nums; }
.copy-answer-btn { margin-left: 2px; }
