/* =========================================================
   "Simple Bud" AI Assistant widget
   Nav-bar trigger + full-height side drawer, injected on every
   page via Site.Master. Self-contained — safe to delete this
   file plus ai-assistant.js and the markup block in
   Site.Master to remove the feature entirely.
   Tokens per design_handoff_ask_ai_fab/README.md (Hybrid: nav
   trigger + side drawer).
   ========================================================= */

:root {
    --ai-primary: #C34533;
    --ai-user-bubble: #7A2E22;
    --ai-retry: #4260C2;
    --ai-light-fill: #FBEAE6;
    --ai-success: #2E8540;
    --ai-error: #CC0202;
    --ai-error-dark: #7A1818;
    --ai-error-fill: #FDECEC;
    --ai-error-border: #F5C2C2;
    --ai-surface: #fff;
    --ai-subtle-fill: #F1F1F3;
    --ai-subtle-fill-2: #F8F9FB;
    --ai-border: #E4E6EB;
    --ai-border-2: #E0E0E0;
    --ai-border-3: #CECECE;
    --ai-text-heading: #00101C;
    --ai-text-body: #272727;
    --ai-text-secondary: #505050;
    --ai-text-muted: #747474;
    --ai-text-faint: #9AA0A6;
    --ai-font: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --ai-font-mono: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* ---------- Nav trigger ---------- */

.ai-nav-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100px;
    margin: 8px 4px;
    background-image: linear-gradient(100deg, #3AA6B0 0%, #4D6FC4 34%, #8464BE 64%, #CE6A50 100%);
    background-size: 135% 100%;
    background-position: 100% 50%;
    background-clip: padding-box;
    border: 1px solid #999;
    border-radius: 8px;
    padding: 5.5px 11px;
    color: #fff;
    font-family: var(--ai-font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background-position 0.45s ease, filter 0.2s ease;
}

.ai-nav-trigger:hover {
    background-position: 0% 50%;
    filter: brightness(1.08);
}

.ai-nav-trigger:focus {
    outline: none;
}

.ai-nav-trigger:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
}

.ai-nav-trigger i {
    font-size: 18px;
}

/* Between the hamburger breakpoint (768px, Bootstrap's own default) and 1300px,
   the navbar is still laid out inline — the existing top nav's own links +
   icons no longer reliably leave room for the full pill+label there, so
   collapse to icon-only (matching the other nav-right icons' footprint)
   rather than let the row overflow and force a page-wide horizontal
   scrollbar. Keyed on viewport width alone (not the JS-toggled
   .navbar-collapse.in class) so there's no dependency on the collapse
   plugin's animation timing. */
@media (min-width: 768px) and (max-width: 1300px) {
    .ai-nav-trigger {
        gap: 0;
        width: auto;
        margin: 8px 1px;
        padding: 7px 6px;
    }

    .ai-nav-trigger span {
        display: none;
    }
}

/* Below 768px the nav becomes the stacked hamburger menu — items have
   plenty of room, so keep the full pill + label (capped so it doesn't
   stretch across the whole menu width). */
@media (max-width: 767px) {
    .ai-nav-trigger {
        width: 100%;
        max-width: 100px;
        justify-content: flex-start;
        padding: 7.5px 14px;
    }
}

/* ---------- Scrim ---------- */

.ai-scrim {
    position: fixed;
    top: var(--ai-top-offset, 0px);
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 16, 28, 0.22);
    z-index: 45;
    display: none;
    animation: ai-fade-in 0.18s;
}

.ai-scrim.ai-open {
    display: block;
}

@keyframes ai-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---------- Drawer ---------- */

.ai-drawer {
    position: fixed;
    right: 0;
    top: var(--ai-top-offset, 0px);
    bottom: 0;
    width: 452px;
    max-width: 92%;
    background: var(--ai-surface);
    box-shadow: -16px 0 48px rgba(0, 16, 28, 0.2);
    display: none;
    flex-direction: column;
    z-index: 46;
    font-family: var(--ai-font);
    animation: ai-slide-left 0.22s ease-out;
}

.ai-drawer.ai-open {
    display: flex;
}

@keyframes ai-slide-left {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

@media (max-width: 640px) {
    .ai-drawer {
        width: 100%;
        max-width: 100%;
    }
}

/* ---------- Header ---------- */

.ai-panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--ai-primary);
    color: #fff;
    flex-shrink: 0;
}

.ai-panel-avatar {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-panel-avatar i {
    font-size: 22px;
}

.ai-panel-title {
    flex: 1;
    min-width: 0;
}

.ai-panel-title strong {
    display: block;
    font-size: 16px;
    line-height: 20px;
    font-weight: 600;
}

.ai-panel-title span {
    display: block;
    font-size: 12px;
    font-weight: 300;
    opacity: 0.9;
    margin-top: 1px;
}

.ai-panel-header button {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s ease;
}

.ai-panel-header button:hover {
    opacity: 0.75;
}

.ai-panel-newchat i,
.ai-panel-close i {
    font-size: 22px;
}

/* ---------- Message area ---------- */

.ai-panel-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    background: var(--ai-surface);
}

.ai-panel-body::-webkit-scrollbar {
    width: 8px;
}

.ai-panel-body::-webkit-scrollbar-thumb {
    background: var(--ai-border-3);
    border-radius: 8px;
}

/* ---------- Welcome state ---------- */

.ai-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 14px;
    padding: 26px 18px 18px;
}

.ai-welcome-avatar {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: var(--ai-light-fill);
    color: var(--ai-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-welcome-avatar i {
    font-size: 26px;
}

.ai-welcome h4 {
    margin: 0;
    font-size: 18px;
    line-height: 24px;
    font-weight: 600;
    color: var(--ai-text-heading);
}

.ai-welcome p {
    margin: 6px 0 0;
    font-size: 14px;
    line-height: 20px;
    font-weight: 300;
    color: var(--ai-text-secondary);
    max-width: 400px;
}

.ai-context-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--ai-subtle-fill);
    border: 1px solid var(--ai-border-2);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ai-text-body);
}

.ai-context-chip i {
    font-size: 16px;
    color: var(--ai-primary);
}

.ai-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.ai-suggestion {
    display: block;
    width: 100%;
    text-align: left;
    padding: 11px 12px;
    border: 1px solid var(--ai-border);
    border-radius: 8px;
    background: var(--ai-surface);
    font-family: inherit;
    font-weight: 300;
    font-size: 13px;
    line-height: 18px;
    color: var(--ai-text-body);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.ai-suggestion:hover {
    background: var(--ai-subtle-fill);
    border-color: var(--ai-border-3);
}

/* ---------- Thread ---------- */

.ai-thread {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-msg-row {
    display: flex;
    gap: 10px;
}

.ai-msg-row.ai-msg-user {
    justify-content: flex-end;
}

.ai-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-avatar i {
    font-size: 18px;
}

.ai-msg-bot .ai-avatar {
    background: var(--ai-light-fill);
    color: var(--ai-primary);
}

.ai-msg-bot.ai-msg-error .ai-avatar {
    background: var(--ai-error-fill);
    color: var(--ai-error);
}

.ai-msg-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-bubble {
    font-size: 14px;
    line-height: 20px;
    font-weight: 300;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.ai-msg-user .ai-bubble {
    max-width: 84%;
    background: var(--ai-user-bubble);
    color: #fff;
    border-radius: 14px 14px 4px 14px;
    padding: 10px 14px;
}

.ai-msg-bot .ai-bubble {
    background: var(--ai-surface);
    color: var(--ai-text-body);
    border: 1px solid var(--ai-border);
    border-radius: 14px 14px 14px 4px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.ai-msg-bot.ai-msg-error .ai-bubble {
    background: var(--ai-error-fill);
    border-color: var(--ai-error-border);
    color: var(--ai-error-dark);
    box-shadow: none;
}

/* ---------- Actions (copy / feedback) ---------- */

.ai-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.ai-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    color: var(--ai-text-secondary);
    font-size: 12px;
    font-family: inherit;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ai-action-btn:hover {
    background: var(--ai-subtle-fill);
    border-color: var(--ai-border);
}

.ai-action-btn i {
    font-size: 16px;
}

.ai-action-btn.ai-action-up.ai-active {
    color: var(--ai-success);
    background: rgba(46, 133, 64, 0.12);
    border-color: rgba(46, 133, 64, 0.35);
}

.ai-action-btn.ai-action-down.ai-active {
    color: var(--ai-error);
    background: rgba(204, 2, 2, 0.1);
    border-color: rgba(204, 2, 2, 0.3);
}

.ai-action-btn.ai-action-copied {
    color: var(--ai-success);
    background: rgba(46, 133, 64, 0.12);
    border-color: rgba(46, 133, 64, 0.35);
}

/* ---------- Follow-up chips ---------- */

.ai-followups {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ai-followup {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--ai-light-fill);
    color: var(--ai-primary);
    border: none;
    border-radius: 999px;
    padding: 5px 11px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}

.ai-followup i {
    font-size: 14px;
}

/* ---------- Error / retry ---------- */

.ai-retry {
    display: flex;
    gap: 10px;
    align-items: center;
}

.ai-retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--ai-retry);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.ai-retry-btn i {
    font-size: 16px;
}

.ai-retry-hint {
    font-size: 12px;
    color: var(--ai-text-muted);
}

/* ---------- Typing indicator ---------- */

.ai-typing-dots {
    background: var(--ai-surface);
    border: 1px solid var(--ai-border);
    border-radius: 14px 14px 14px 4px;
    padding: 14px 16px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.ai-typing-dots i {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: var(--ai-text-faint);
    display: inline-block;
    animation: ai-typing-blink 1.2s infinite;
}

.ai-typing-dots i:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dots i:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-typing-blink {
    0%, 80%, 100% { opacity: 0.25; }
    40% { opacity: 1; }
}

/* ---------- Input area ---------- */

.ai-panel-footer {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--ai-border-2);
    background: var(--ai-surface);
}

.ai-panel-disclaimer {
    flex-shrink: 0;
    padding: 0 12px 10px;
    text-align: center;
    font-size: 11px;
    line-height: 1.4;
    color: var(--ai-text-muted);
    background: var(--ai-surface);
}

.ai-input {
    flex: 1;
    box-sizing: content-box;
    resize: none;
    border: 1px solid var(--ai-border-3);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: inherit;
    font-weight: 300;
    font-size: 14px;
    line-height: 20px;
    height: 60px;
    overflow-y: hidden;
    outline: none;
    color: #111;
    transition: border-color 0.15s ease;
}

.ai-input:focus {
    border-color: var(--ai-primary);
}

.ai-send {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    flex-shrink: 0;
    background: var(--ai-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.ai-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ai-send i {
    font-size: 22px;
}
