/* AI Assistant Widget */

/* Brand palette — mirrors the app-wide colors used across style.css/custom.css */
:root {
    --aiw-blue: #0077c6; /* primary brand blue (buttons, accents) */
    --aiw-blue-dark: #0063a9; /* darker blue for hover states */
    --aiw-blue-link: #0173bd; /* link / accent text */
    --aiw-gradient: linear-gradient(180deg, #0077c6 0%, #0063a9 100%);
    --aiw-light: #c1e6ff; /* light-blue highlight (active/hover backgrounds) */
    --aiw-border: #dfdfdf; /* hairline border */
    --aiw-red: #d4032e; /* primary action red (matches .save-button in custom.css) */
    --aiw-red-dark: #b00227; /* darker red for hover states */

    /* In-chat form palette — neutral greys (matches the client-summary card look) */
    --aiw-form-label: #5f6368; /* field labels */
    --aiw-disclaimer-text: #8a9096; /* disclaimer under the input */
    --aiw-form-text: #3c4043; /* input / value text + form title */
    --aiw-form-border: #dadce0; /* input borders */
    --aiw-form-focus: #80868b; /* input border on focus */
}

/* Shared anchor for the floating trigger and panel.
   z-index sits above Bootstrap's overlay band (backdrop 1040 … tooltip 1070) so the
   assistant stays reachable on top of modals/popovers, like a support widget. */
.ai-widget-trigger,
.ai-widget-panel {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1080;
}

/* Trigger */
.ai-widget-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    padding: 0;
    /* Thin white ring so the button stays visible on the blue footer/header bars.
       Drawn as a shadow, not a border, so it does not eat into the 56px circle. */
    border: none;
    border-radius: 50%;
    background: var(--aiw-gradient);
    color: #fff;
    cursor: pointer;
    box-shadow:
        0 0 0 2px #fff,
        0 4px 20px rgba(0, 102, 204, 0.4);
    transition:
        transform 0.2s,
        box-shadow 0.2s;
}

.ai-widget-trigger:hover {
    transform: scale(1.1);
    box-shadow:
        0 0 0 2px #fff,
        0 6px 30px rgba(0, 102, 204, 0.5);
}

/* Font Awesome fa-robot; the size classes set the glyph size for the trigger and the header. */
.ai-widget-robot-icon--lg {
    font-size: 28px;
}

.ai-widget-robot-icon--sm {
    font-size: 18px;
}

/* Panel */
.ai-widget-panel {
    display: flex;
    flex-direction: column;
    /* Wide enough for four 100px quick-action tiles per row in the expanded grid. */
    width: 500px;
    height: 580px;
    max-height: calc(100vh - 48px);
    overflow: hidden;
    border: 1px solid var(--aiw-border);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
    /* Fast animation when toggling maximize/minimize. Only explicit (non-auto)
       values are used in both states so width/right/etc. can actually tween. */
    transition:
        width 0.15s ease,
        height 0.15s ease,
        right 0.15s ease,
        bottom 0.15s ease,
        border-radius 0.15s ease;
}

/* Maximized within the content column, with the sidebar visible and background dimmed. */
.ai-widget-panel.maximized {
    right: 20px;
    bottom: 20px;
    width: calc(100vw - var(--content-left, 70px) - 40px);
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
    border-radius: 8px;
    box-shadow: 0 0 0 100vmax rgba(15, 23, 42, .45), 0 8px 40px rgba(0, 0, 0, .2);
}

/* Header */
.ai-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    padding: 12px 14px;
    background: var(--aiw-gradient);
    color: #fff;
}

.ai-widget-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
}

.ai-widget-controls {
    display: flex;
    gap: 4px;
}

.ai-widget-controls button {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
}

.ai-widget-controls button:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* Context banner. The base is the neutral light-blue bar; the profile-state modifiers
   below tint it (blue/green/yellow) to signal data completeness (see the Section 1
   spec). */
.ai-widget-context {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    padding: 10px 14px;
    border-bottom: 1px solid var(--aiw-border);
    background: var(--aiw-light);
    color: var(--aiw-blue-link);
    font-size: 12px;
}

.ai-widget-context--complete {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-bottom-color: #90caf9;
}

.ai-widget-context--resolved {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    border-bottom-color: #66bb6a;
}

.ai-widget-context--incomplete,
.ai-widget-context--new {
    background: linear-gradient(135deg, #fff8e1 0%, #ffecb3 100%);
    border-bottom-color: #ffc107;
}

.ai-widget-context-client {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-widget-avatar {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #0066cc;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
}

.ai-widget-avatar--placeholder {
    background: #9e9e9e;
}

/* Scoped under the banner container so these don't collide at equal specificity with the
   search-card rules for the same class names later in this file (which would otherwise win
   on source order and drop the banner's colors). */
.ai-widget-context-client .ai-widget-client-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.ai-widget-context-client .ai-widget-client-name {
    font-weight: 600;
    color: #0d47a1;
}

.ai-widget-context-client .ai-widget-client-meta {
    font-size: 11px;
    color: #1565c0;
}

.ai-widget-context-client .ai-widget-client-meta--warning {
    color: #e65100;
}

/* State abbreviation carries a full-name tooltip on hover. */
.ai-widget-meta-state {
    cursor: help;
    border-bottom: 1px dotted currentColor;
}

/* Neutral pill — the amount is informational, not a severity signal, so it is not
   color-coded; a small "Liability" label makes the figure self-explanatory. */
.ai-widget-liability-badge {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 3px 10px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--aiw-border);
    line-height: 1.2;
}

.ai-widget-liability-label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--aiw-form-label);
}

.ai-widget-liability-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--aiw-form-text);
}

.ai-widget-context-tags {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.ai-widget-tag {
    padding: 2px 8px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid #90caf9;
    color: #1565c0;
    font-size: 10px;
}

.ai-widget-tag--warning {
    background: #fff3cd;
    border-color: #ffc107;
    color: #856404;
}

.ai-widget-tag--success {
    background: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.ai-widget-tag--error {
    background: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.ai-widget-tag--clickable {
    cursor: pointer;
}

.ai-widget-tag--clickable:hover {
    filter: brightness(0.96);
    text-decoration: underline;
}

.ai-widget-page-badge {
    margin-left: auto;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--aiw-blue);
    color: #fff;
    font-size: 10px;
    font-weight: 500;
}

/* Welcome state callout (rendered under the welcome bubble) */
.ai-widget-notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 12px;
}

.ai-widget-notice .fa {
    font-size: 15px;
    margin-top: 1px;
}

.ai-widget-notice-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-widget-notice-title {
    font-weight: 600;
}

.ai-widget-notice--success {
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    color: #2e7d32;
}

.ai-widget-notice--info {
    background: #e3f2fd;
    border: 1px solid #90caf9;
    color: #0d47a1;
}

/* History */
.ai-widget-history-panel {
    /* May shrink: in a short window (high browser zoom) a fixed height would push the
       input row out of the panel. */
    flex-shrink: 1;
    min-height: 48px;
    max-height: 220px;
    overflow-y: auto;
    border-bottom: 1px solid var(--aiw-border);
    background: #fff;
}

.ai-widget-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--aiw-border);
    color: #333;
    font-size: 12px;
    font-weight: 600;
}

.ai-widget-history-header button {
    padding: 3px 8px;
    border: none;
    border-radius: 4px;
    background: var(--aiw-blue);
    color: #fff;
    font-size: 10px;
    cursor: pointer;
}

.ai-widget-history-group-label {
    padding: 4px 12px;
    color: #999;
    font-size: 10px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.ai-widget-history-item {
    display: flex;
    align-items: center;
    padding: 7px 12px;
    border-left: 3px solid transparent;
    color: #333;
    font-size: 12px;
    cursor: pointer;
}

.ai-widget-history-item:hover {
    background: var(--aiw-light);
}

.ai-widget-history-item.active {
    border-left-color: var(--aiw-blue);
    background: var(--aiw-light);
}

.ai-widget-history-item-title {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.ai-widget-history-delete {
    padding: 2px 4px;
    border: none;
    background: none;
    color: #ccc;
    font-size: 11px;
    cursor: pointer;
}

.ai-widget-history-delete:hover {
    color: #dc3545;
}

.ai-widget-history-empty {
    padding: 12px;
    color: #999;
    font-size: 12px;
    text-align: center;
}

/* Messages */
.ai-widget-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #fafafa;
}

.ai-widget-message {
    max-width: 88%;
}

.ai-widget-load-earlier {
    align-self: center;
    flex-shrink: 0;
    padding: 4px 12px;
    border: 1px solid var(--aiw-border);
    border-radius: 12px;
    background: #fff;
    color: var(--aiw-blue-link);
    font-size: 11px;
    cursor: pointer;
}

.ai-widget-load-earlier:disabled {
    opacity: 0.5;
    cursor: default;
}

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

.ai-widget-message.assistant {
    align-self: flex-start;
}

/* An in-chat form/widget spans the full panel width (not the 88% chat-bubble cap)
   so its inline label + input rows have room to breathe. */
.ai-widget-message.widget {
    max-width: 100%;
    align-self: stretch;
}

.ai-widget-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    /* A wide table scrolls inside the bubble instead of crossing its border. */
    overflow-x: auto;
}

.ai-widget-bubble p {
    margin: 0 0 6px;
}

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

.ai-widget-message.user .ai-widget-bubble {
    border-bottom-right-radius: 4px;
    background: var(--aiw-blue);
    color: #fff;
}

.ai-widget-message.assistant .ai-widget-bubble {
    border: 1px solid var(--aiw-border);
    border-bottom-left-radius: 4px;
    background: #fff;
    color: #333;
}

.ai-widget-message.error .ai-widget-bubble {
    border-color: #ef9a9a;
    background: #ffebee;
    color: #c62828;
}

/* The streaming bubble holds rendered markdown like the final one, so line breaks come
   from the markup, not from preserved whitespace. */
.ai-widget-streaming {
    overflow-wrap: break-word;
}

/* The caret sits inside the last rendered block, otherwise it would start a block of
   its own below the text. */
.ai-widget-streaming > :last-child::after {
    content: '';
    display: inline-block;
    width: 7px;
    height: 14px;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: var(--aiw-blue);
    animation: ai-widget-caret 1s steps(1) infinite;
}

@keyframes ai-widget-caret {
    50% {
        opacity: 0;
    }
}

/* Typing indicator */
.ai-widget-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    border: 1px solid var(--aiw-border);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    background: #fff;
}

/* Animated dots only — exclude the label span, which is also a direct child */
.ai-widget-typing > span:not(.ai-widget-typing-label) {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #999;
    animation: ai-widget-bounce 1.4s infinite ease-in-out;
}

.ai-widget-typing > span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-widget-typing > span:nth-child(3) {
    animation-delay: 0.4s;
}

.ai-widget-typing-label {
    margin-left: 4px;
    color: #888;
    font-size: 11px;
}

@keyframes ai-widget-bounce {
    0%,
    80%,
    100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-5px);
    }
}

/* Citation */
.ai-widget-citation {
    margin-top: 6px;
    padding: 8px 10px;
    border: 1px solid #ffe082;
    border-radius: 6px;
    background: #fff8e1;
    color: #555;
    font-size: 13px;
}

.ai-widget-citation-header {
    display: flex;
    align-items: center;
    gap: 5px;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: #f57c00;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.ai-widget-citation-title {
    flex: 1;
}

.ai-widget-citation-chevron {
    font-size: 11px;
}

.ai-widget-citation-body {
    margin-top: 6px;
}

.ai-widget-citation p {
    margin: 0 0 4px;
}

.ai-widget-citation a {
    color: var(--aiw-blue-link);
    text-decoration: none;
}

.ai-widget-citation a:hover {
    text-decoration: underline;
}

/* Video tutorial source — an external YouTube link built by the server */
/* Source type label (IRM, Workshop, Expert Advice, Support, Video tutorial) that
   opens every source line, built server-side in buildSourcesReference. */
.ai-widget-source-type {
    display: inline-block;
    margin-right: 6px;
    padding: 0 6px;
    border-radius: 3px;
    background: var(--aiw-border);
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    color: var(--aiw-form-label);
    vertical-align: middle;
}

/* Heading before the sources the model read but did not cite in the answer */
.ai-widget-sources-consulted {
    margin: 10px 0 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--aiw-form-label);
}

/* Knowledge base excerpt — the retrieved chunks rendered from markdown under their
   source line. Tag selectors are scoped here because the HTML comes from Parsedown. */
.ai-widget-source-kb-text {
    margin: 0 0 10px 20px;
    padding-left: 10px;
    border-left: 2px solid var(--aiw-border);
    font-size: 12px;
    color: var(--aiw-form-text);
}

.ai-widget-source-kb-text h1,
.ai-widget-source-kb-text h2,
.ai-widget-source-kb-text h3,
.ai-widget-source-kb-text h4 {
    margin: 6px 0 2px;
    font-size: 12px;
    font-weight: 600;
    color: var(--aiw-form-label);
}

.ai-widget-source-kb-text ul,
.ai-widget-source-kb-text ol {
    margin: 0 0 4px;
    padding-left: 18px;
}

.ai-widget-source-kb-text hr {
    margin: 6px 0;
    border: 0;
    border-top: 1px solid var(--aiw-border);
}

/* Research trail: an open list while the answer is prepared, a collapsed block after */
.ai-widget-trail {
    margin-bottom: 6px;
    padding: 8px 10px;
    border: 1px solid var(--aiw-border);
    border-radius: 6px;
    background: #fafafa;
    color: #555;
    font-size: 13px;
}

.ai-widget-trail-header {
    display: flex;
    align-items: center;
    gap: 5px;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: #777;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
}

.ai-widget-trail-toggle {
    cursor: pointer;
}

.ai-widget-trail-title {
    flex: 1;
}

.ai-widget-trail-chevron {
    font-size: 11px;
}

.ai-widget-trail-body {
    margin: 6px 0 0;
    padding: 0;
    list-style: none;
}

.ai-widget-trail-step {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 3px;
}

.ai-widget-trail-icon {
    width: 14px;
    color: #999;
    font-size: 12px;
    text-align: center;
}

.ai-widget-trail-step .ai-widget-source-type {
    margin-right: 0;
}

.ai-widget-trail-label {
    flex: 1;
    min-width: 0;
}

/* Follow-up question chips under a finished answer */
.ai-widget-followups {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

/* Own line above the chips, so they do not read as part of the Sources block. */
.ai-widget-followups-label {
    flex-basis: 100%;
    color: #999;
    font-size: 10px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.ai-widget-followup-chip {
    padding: 5px 10px;
    border: 1px solid var(--aiw-blue-link);
    border-radius: 14px;
    background: #fff;
    color: var(--aiw-blue-link);
    font-size: 12px;
    text-align: left;
    cursor: pointer;
}

.ai-widget-followup-chip:hover:not(:disabled) {
    background: #eaf4ff;
}

.ai-widget-followup-chip:disabled,
.ai-widget-chip:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Input */
.ai-widget-input-area {
    flex-shrink: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--aiw-border);
    background: #fff;
}

/* Single scrollable row with AI actions*/
.ai-widget-quick-actions {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
    overflow-x: auto;
}

.ai-widget-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 4px 9px;
    border: 1px solid var(--aiw-blue);
    border-radius: 12px;
    background: #fff;
    color: var(--aiw-blue);
    font-size: 10px;
    cursor: pointer;
    transition:
        background 0.15s,
        color 0.15s;
}

.ai-widget-chip:hover:not(:disabled) {
    background: var(--aiw-blue);
    color: #fff;
}

.ai-widget-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.ai-widget-textarea {
    flex: 1;
    min-height: 38px;
    max-height: 100px;
    overflow-y: auto;
    padding: 9px 12px;
    border: 1px solid var(--aiw-border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    resize: none;
}

.ai-widget-textarea:focus {
    outline: none;
    border-color: var(--aiw-blue);
}

.ai-widget-send {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 8px;
    background: var(--aiw-blue);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.ai-widget-send:hover:not([disabled]) {
    background: var(--aiw-blue-dark);
}

.ai-widget-send[disabled] {
    background: #bbb;
    cursor: default;
}

/* Voice mode (spec state 21) */
.ai-widget-controls .ai-widget-voice-toggle--active {
    background: #fff;
    color: var(--aiw-blue);
}

.ai-widget-mic {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: 1px solid var(--aiw-border);
    border-radius: 50%;
    background: #fff;
    color: var(--aiw-blue);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.ai-widget-mic:hover:not([disabled]) {
    background: #f0f6fb;
}

.ai-widget-mic[disabled] {
    color: #bbb;
    cursor: default;
}

.ai-widget-mic--listening {
    border-color: var(--aiw-red);
    background: rgba(212, 3, 46, 0.12);
    color: var(--aiw-red);
    animation: ai-widget-pulse 1.4s ease-out infinite;
}

/* Sticky inside the scrolling messages column, so it stays in the bottom-right corner
   while the transcript scrolls. */
.ai-widget-voice-avatar {
    position: sticky;
    bottom: 0;
    align-self: flex-end;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-top: auto;
    cursor: grab;
    user-select: none;
}

.ai-widget-voice-face {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 84px;
    height: 84px;
    border-radius: 50%;
    border: 3px solid #b8d4ec;
    background: radial-gradient(circle at 50% 30%, #ffffff 0%, #e8f2ff 40%, #b8d4ec 100%);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
    transition: border-color 0.2s;
}

/* The mascot images have a white background; multiply blending hides it on the
   light circle. */
.ai-widget-voice-face img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    mix-blend-mode: multiply;
}

.ai-widget-voice-status {
    padding: 2px 8px;
    border: 1px solid #b8d4ec;
    border-radius: 8px;
    background: #fff;
    color: var(--aiw-blue);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.ai-widget-voice-avatar--listening .ai-widget-voice-face {
    border-color: var(--aiw-red);
    animation: ai-widget-pulse 1.4s ease-out infinite;
}

.ai-widget-voice-avatar--thinking .ai-widget-voice-face {
    border-color: #f0ad4e;
}

.ai-widget-voice-avatar--talking .ai-widget-voice-face {
    border-color: var(--aiw-blue);
}

@keyframes ai-widget-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(212, 3, 46, 0.35);
    }
    100% {
        box-shadow: 0 0 0 12px rgba(212, 3, 46, 0);
    }
}

/* Keyboard focus visibility. Blue ring on light surfaces; white ring for the header
   controls, which sit on the blue gradient where a blue ring would have no contrast. */
.ai-widget-trigger:focus-visible,
.ai-widget-history-header button:focus-visible,
.ai-widget-history-delete:focus-visible,
.ai-widget-chip:focus-visible,
.ai-widget-send:focus-visible,
.ai-widget-textarea:focus-visible {
    outline: 2px solid var(--aiw-blue);
    outline-offset: 2px;
}

.ai-widget-controls button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* Small screens: fill the viewport */
@media (max-width: 480px) {
    .ai-widget-panel {
        right: 12px;
        bottom: 12px;
        width: calc(100vw - 24px);
        height: calc(100vh - 24px);
    }

    .ai-widget-trigger {
        right: 16px;
        bottom: 16px;
    }
}

/* Respect users who prefer reduced motion: drop the hover scale, the streaming
   caret blink, and the typing-dot bounce (they stay visible, just static). */
@media (prefers-reduced-motion: reduce) {
    .ai-widget-trigger,
    .ai-widget-chip,
    .ai-widget-send,
    .ai-widget-qa-main {
        transition: none;
    }

    .ai-widget-trigger:hover {
        transform: none;
    }

    .ai-widget-streaming::after,
    .ai-widget-typing > span:not(.ai-widget-typing-label) {
        animation: none;
    }
}

.ai-widget-form-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--aiw-form-text);
    margin-bottom: 8px;
}

/* Secondary line under the form title (e.g. the rename form's "Current name: …"). */
.ai-widget-form-subtitle {
    font-size: 12px;
    color: var(--aiw-form-text);
    margin-bottom: 8px;
}

/* A button under a reply that opens the page the reply names (page_link widget). */
.ai-widget-page-link {
    display: flex;
}

/* A list of options the user picks one from (option_list widget). */
.ai-widget-option-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai-widget-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    padding: 8px 12px;
    text-align: left;
    background: #fff;
    border: 1px solid var(--aiw-border);
    border-radius: 8px;
    cursor: pointer;
    transition:
        background 0.15s ease,
        border-color 0.15s ease;
}

.ai-widget-option:hover:not(:disabled) {
    background: #f1f3f4;
    border-color: var(--aiw-blue);
}

.ai-widget-option:active:not(:disabled) {
    background: #e3e8ee;
    border-color: var(--aiw-blue-dark);
}

.ai-widget-option:disabled {
    opacity: 0.6;
    cursor: default;
}

.ai-widget-option--chosen:disabled {
    border-color: var(--aiw-blue);
    opacity: 1;
}

.ai-widget-option-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--aiw-blue);
}

.ai-widget-option-description {
    font-size: 11px;
    color: var(--aiw-form-label);
}

/* In-chat read-only data table (data_table widget) — structured data display. */
.ai-widget-table-card {
    border: 1px solid var(--aiw-form-border);
    border-radius: 10px;
    padding: 12px;
    background: #fff;
}

/* Scrolls both ways: horizontally for wide tables, vertically past 200px (the
   header row stays pinned via position: sticky). */
.ai-widget-table-scroll {
    overflow: auto;
    max-height: 200px;
    border-radius: 6px;
}

/* border-collapse: separate (not collapse) — collapsed borders detach from a sticky
   header and scroll away with the body; here each cell owns its bottom border. */
.ai-widget-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
    color: var(--aiw-form-text);
}

.ai-widget-table-header-cell {
    position: sticky;
    top: 0;
    background: #f5f5f5;
    font-size: 11px;
    font-weight: 600;
    text-align: left;
}

.ai-widget-table-header-cell,
.ai-widget-table-cell {
    padding: 8px 12px;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
}

.ai-widget-table-total-cell {
    background: #e6f2ff;
    font-weight: 600;
}

/* Last so it wins over the header cell's text-align: left at equal specificity. */
.ai-widget-table-right {
    text-align: right;
}

/* ---- Row of a list with a per-row action. Introduced for the form preparation
       checklist (form_checklist widget, spec state 11); the form draft widgets reuse
       the item rules for their list of the client's existing copies. ---- */

.ai-widget-checklist-card {
    border: 1px solid var(--aiw-form-border);
    border-radius: 10px;
    padding: 12px;
    background: #fff;
}

.ai-widget-checklist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 12px;
    color: var(--aiw-form-text);
}

.ai-widget-checklist-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.ai-widget-checklist-icon--complete {
    color: #1b7a3d;
}

.ai-widget-checklist-icon--partial {
    color: #f57c00;
}

.ai-widget-checklist-icon--empty {
    color: #bdbdbd;
}

.ai-widget-checklist-label {
    flex: 1;
}

.ai-widget-checklist-status {
    font-size: 11px;
    font-weight: 600;
    color: #f57c00;
}

.ai-widget-checklist-action {
    border: 1px solid #0066cc;
    background: #fff;
    color: #0066cc;
    border-radius: 12px;
    padding: 3px 12px;
    font-size: 11px;
    cursor: pointer;
}

.ai-widget-checklist-action:hover {
    background: #0066cc;
    color: #fff;
}

/* ---- Client search results widget (client_search_results, spec states 9-11) ---- */

.ai-widget-search-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-widget-client-card {
    padding: 12px;
    background: #fff;
    border: 1px solid var(--aiw-border);
    border-radius: 8px;
}

.ai-widget-client-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-widget-client-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--aiw-gradient);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
}

.ai-widget-client-info {
    flex: 1;
    min-width: 0;
}

.ai-widget-client-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--aiw-form-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-widget-client-meta {
    font-size: 12px;
    color: var(--aiw-form-label);
}

.ai-widget-client-amount {
    font-size: 15px;
    font-weight: 600;
    color: var(--aiw-form-text);
    text-align: right;
}

/* Status pill on compact search-result cards. Active is subtle; closed/inactive is
   flagged so it's clear the client is outside the grid's default Active view. */
.ai-widget-client-status {
    margin-top: 4px;
}

.ai-widget-status-pill {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    background: #e8f5e9;
    color: #2e7d32;
}

.ai-widget-status-pill--closed {
    background: #fff3cd;
    color: #856404;
}

.ai-widget-client-details {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--aiw-border);
}

.ai-widget-detail-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--aiw-form-text);
}

.ai-widget-detail-label {
    color: var(--aiw-form-label);
}

.ai-widget-client-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.ai-widget-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 1;
    height: 32px;
    padding: 0 12px;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    transition:
        background 0.15s ease,
        border-color 0.15s ease;
}

.ai-widget-action-primary {
    color: #fff;
    background: var(--aiw-blue);
    border: 1px solid var(--aiw-blue);
}

.ai-widget-action-primary:hover:not(:disabled) {
    background: var(--aiw-blue-dark);
    border-color: var(--aiw-blue-dark);
}

.ai-widget-action-primary:disabled {
    opacity: 0.7;
    cursor: default;
}

.ai-widget-action-secondary {
    color: var(--aiw-form-text);
    background: #fff;
    border: 1px solid var(--aiw-form-border);
}

.ai-widget-action-secondary:hover {
    background: var(--aiw-light);
    border-color: var(--aiw-blue);
}

/* Compact Select on multi-result cards — sits at the right end of the header row. */
.ai-widget-select-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    height: 26px;
    padding: 0 10px;
    font-size: 12px;
    color: #fff;
    background: var(--aiw-blue);
    border: 1px solid var(--aiw-blue);
    border-radius: 6px;
    cursor: pointer;
    transition:
        background 0.15s ease,
        border-color 0.15s ease;
}

.ai-widget-select-btn:hover:not(:disabled) {
    background: var(--aiw-blue-dark);
    border-color: var(--aiw-blue-dark);
}

.ai-widget-select-btn:disabled {
    opacity: 0.7;
    cursor: default;
}

.ai-widget-search-empty {
    padding: 16px;
    background: #fff;
    border: 1px solid var(--aiw-border);
    border-radius: 8px;
    text-align: center;
}

.ai-widget-search-empty .fa-search {
    font-size: 22px;
    color: var(--aiw-form-label);
    margin-bottom: 8px;
}

.ai-widget-search-empty-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--aiw-form-text);
    margin-bottom: 4px;
}

.ai-widget-search-empty-text {
    font-size: 12px;
    color: var(--aiw-form-label);
    margin-bottom: 4px;
}

/* Info bubble with an inline action (e.g. "Navigate to client" after selecting):
   text on the left, a select-style button on the right. */
.ai-widget-bubble-with-action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

/* Quick-actions row: the chips line plus the expand/collapse toggle on the right. */
.ai-widget-quick-actions-row {
    display: flex;
    align-items: flex-start;
    gap: 5px;
    margin-bottom: 8px;
}

.ai-widget-qa-main {
    flex: 1;
    min-width: 0;
    /* Animate expand/collapse: max-height tweens between the collapsed single line
       and the expanded block (height: auto would snap). */
    max-height: 40px;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.ai-widget-quick-actions-row .ai-widget-quick-actions {
    margin-bottom: 0;
}

.ai-widget-qa-title {
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--aiw-form-text);
}

/* Chip descriptions only show on the expanded square tiles. */
.ai-widget-chip-desc {
    display: none;
}

.ai-widget-qa-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--aiw-blue);
    border-radius: 50%;
    background: #fff;
    color: var(--aiw-blue);
    font-size: 10px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ai-widget-qa-toggle:hover {
    background: var(--aiw-light);
}

/* Expanded: a titled block capped at 40% of the panel height (580px default panel,
   95vh maximized — keep in sync with .ai-widget-panel) holding square action tiles. */
.ai-widget-panel.qa-expanded .ai-widget-qa-main {
    display: flex;
    flex-direction: column;
    /* The 30vh limit only applies in a short window (high browser zoom), where the
       full block would push the input row out of the panel. */
    max-height: min(calc(580px * 0.4), 30vh);
}

.ai-widget-panel.maximized.qa-expanded .ai-widget-qa-main {
    max-height: calc(95vh * 0.4);
}

.ai-widget-panel.qa-expanded .ai-widget-quick-actions {
    flex: 1;
    flex-wrap: wrap;
    align-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
}

/* The pill chips become square tiles: icon on top, name, short description. */
.ai-widget-panel.qa-expanded .ai-widget-chip {
    flex-direction: column;
    justify-content: flex-start;
    gap: 5px;
    width: 100px;
    min-height: 100px;
    padding: 10px 8px;
    border-radius: 8px;
    white-space: normal;
    text-align: center;
}

.ai-widget-panel.qa-expanded .ai-widget-chip .fa {
    font-size: 16px;
}

.ai-widget-panel.qa-expanded .ai-widget-chip-name {
    font-weight: 600;
    line-height: 1.2;
}

.ai-widget-panel.qa-expanded .ai-widget-chip-desc {
    display: block;
    font-size: 9px;
    line-height: 1.3;
    color: var(--aiw-form-label);
}

/* Tiles hover light gray (the pills' deep-blue hover makes tile text unreadable). */
.ai-widget-panel.qa-expanded .ai-widget-chip:hover:not(:disabled) {
    background: #f1f3f4;
    color: var(--aiw-blue);
}

/* Page actions: while the assistant changes the page behind the panel, the panel lets
   the page show through. */
.ai-widget-panel--see-through {
    opacity: 0.6;
    transition: opacity 0.2s;
}

/* What the assistant is doing now, next to the title. */
.ai-widget-state {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.9;
}

.ai-widget-robot-icon--thinking,
.ai-widget-robot-icon--answering,
.ai-widget-robot-icon--acting {
    animation: ai-widget-state-pulse 1.2s ease-in-out infinite;
}

@keyframes ai-widget-state-pulse {
    50% {
        opacity: 0.45;
    }
}

.ai-widget-stop {
    padding: 2px 10px;
    border: 1px solid #fff;
    border-radius: 4px;
    background: #fff;
    color: var(--aiw-blue);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.ai-widget-stop:hover:not([disabled]) {
    background: var(--aiw-light);
}

.ai-widget-stop:active:not([disabled]) {
    background: #9fd4f7;
}

.ai-widget-stop:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.ai-widget-stop[disabled] {
    border-color: #bbb;
    background: #bbb;
    color: #fff;
    cursor: default;
}

/* The line under the input: the assistant can make mistakes. */
.ai-widget-disclaimer {
    margin: 8px 0 0;
    color: var(--aiw-disclaimer-text);
    font-size: 10px;
    line-height: 1.35;
}

.ai-widget-disclaimer-link {
    color: var(--aiw-blue-link);
    text-decoration: underline;
}

/* Rating of an answer: thumbs under the bubble and the optional comment form. */
.ai-widget-feedback {
    margin-top: 8px;
}

.ai-widget-feedback-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-widget-feedback-button {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--aiw-form-border);
    border-radius: 6px;
    background: #fff;
    color: var(--aiw-form-label);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.ai-widget-feedback-button:hover:not(:disabled) {
    border-color: var(--aiw-blue-link);
    background: #eaf4ff;
    color: var(--aiw-blue-link);
}

.ai-widget-feedback-button:active:not(:disabled) {
    background: var(--aiw-light);
}

.ai-widget-feedback-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-widget-feedback-button--chosen {
    border-color: var(--aiw-blue);
    background: var(--aiw-light);
    color: var(--aiw-blue-dark);
}

.ai-widget-feedback-label {
    color: var(--aiw-form-label);
    font-size: 11px;
}

.ai-widget-feedback-comment {
    margin-top: 8px;
    padding: 10px;
    border: 1px solid var(--aiw-form-border);
    border-radius: 8px;
    background: #fff;
}

.ai-widget-feedback-comment-label {
    display: block;
    margin: 0;
    color: var(--aiw-form-text);
    font-size: 12px;
    font-weight: 600;
}

.ai-widget-feedback-comment-input {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 6px 8px;
    border: 1px solid var(--aiw-form-border);
    border-radius: 6px;
    color: var(--aiw-form-text);
    font-size: 12px;
    font-weight: 400;
    resize: vertical;
}

.ai-widget-feedback-comment-input:focus {
    border-color: var(--aiw-form-focus);
    outline: none;
}

.ai-widget-feedback-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.ai-widget-feedback-skip,
.ai-widget-feedback-send {
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.ai-widget-feedback-skip {
    border: 1px solid transparent;
    background: transparent;
    color: var(--aiw-form-label);
}

.ai-widget-feedback-skip:hover {
    background: #f1f3f4;
}

.ai-widget-feedback-skip:active {
    background: #e3e6e8;
}

.ai-widget-feedback-send {
    border: 1px solid var(--aiw-blue);
    background: var(--aiw-blue);
    color: #fff;
}

.ai-widget-feedback-send:hover:not(:disabled) {
    border-color: var(--aiw-blue-dark);
    background: var(--aiw-blue-dark);
}

.ai-widget-feedback-send:active:not(:disabled) {
    background: #00548f;
}

.ai-widget-feedback-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* The notice about the use of questions and ratings, above the messages. */
.ai-widget-feedback-notice {
    display: flex;
    flex-shrink: 0;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--aiw-border);
    background: #f4f9fd;
    color: var(--aiw-form-text);
    font-size: 11px;
    line-height: 1.35;
}

.ai-widget-feedback-notice-icon {
    margin-top: 2px;
    color: var(--aiw-blue-link);
}

.ai-widget-feedback-notice-text {
    flex: 1;
}

.ai-widget-feedback-notice-link {
    color: var(--aiw-blue-link);
    font-weight: 600;
    text-decoration: underline;
}

.ai-widget-feedback-notice-close {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--aiw-form-label);
    cursor: pointer;
    transition: background 0.15s;
}

.ai-widget-feedback-notice-close:hover {
    background: var(--aiw-light);
}

.ai-widget-feedback-notice-close:active {
    background: #a9d9fb;
}

/* A form field the assistant has filled (AiFillHighlight). */
.ai-fill-highlight {
    /* A form field tag is inline by default, and an inline box gets no full frame. */
    display: block;
    border-radius: 4px;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.55);
    transition: box-shadow 0.2s;
}

@media (prefers-reduced-motion: reduce) {
    .ai-widget-robot-icon--thinking,
    .ai-widget-robot-icon--answering,
    .ai-widget-robot-icon--acting {
        animation: none;
    }

    .ai-widget-panel--see-through,
    .ai-fill-highlight {
        transition: none;
    }
}
