/* ============================================================
   In-App Expert — right-side chat drawer (Phase 1)
   All colors via the managed color system (master-colors.css).
   ============================================================ */

/* ---- Launch button ---- */
.assistant-launch-btn {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1190;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--ui-text-linkText);
    color: var(--ui-backgrounds-cardBg);
    font-size: 22px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(var(--color-blue-6-rgb), 0.35);
    transition: transform 0.18s ease, background 0.18s ease;
}
.assistant-launch-btn:hover {
    background: var(--ui-main-linkHover);
    transform: scale(1.06);
}
.assistant-launch-btn:focus-visible {
    outline: 2px solid var(--ui-borders-borderFocus);
    outline-offset: 2px;
}
.assistant-launch-btn.assistant-hidden { display: none; }

/* ---- Drawer shell ---- */
.assistant-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 400px;
    max-width: 100vw;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    background: var(--ui-backgrounds-panelBg);
    border-left: 1px solid var(--ui-borders-borderDefault);
    box-shadow: -6px 0 24px rgba(var(--color-ui-shadow-rgb), 0.18);
    transform: translateX(102%);
    /* Closed = hidden once it has slid out (review 2026-10-24): at 520px or less the closed drawer is a full-width
       fixed dialog with a Close button, so the popup guard (js/framework/popupDismissGuard.js) took it for an open
       popup and swallowed every Escape on the page. Hidden also keeps its controls out of the tab order. */
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
}
.assistant-drawer.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.2s ease, visibility 0s;
}

@media (max-width: 520px) {
    .assistant-drawer { width: 100vw; }
}

/* ---- Header ---- */
.assistant-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--ui-borders-borderDefault);
    background: var(--ui-main-contentHeaderBg);
}
.assistant-header-title {
    flex: 1;
    font-size: 15px;
    font-weight: 700;
    color: var(--ui-main-headerText);
}
.assistant-header-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 2px 7px;
    border-radius: 999px;
    /* On the dark header: the header's own text colour on a light wash (blue on it barely showed). */
    background: rgba(var(--color-ui-header-text-rgb), 0.18);
    color: var(--ui-main-headerText, var(--color-ui-header-text));
}
/* The mode switch (AI Chat P2-04): the app's slate pill (PillToggle), full
   width, with one line under it saying what the mode can see and do. */
.assistant-mode-bar {
    padding: 10px 16px 8px;
    border-bottom: 1px solid var(--ui-borders-borderDefault);
    background: var(--ui-backgrounds-panelBg);
}
.assistant-mode-bar .assistant-mode-control { width: 100%; }
.assistant-mode-line { margin-top: 6px; line-height: 1.4; }
/* Fallback when the page has no SegmentedControl: plain buttons. */
.assistant-mode-buttons {
    display: flex;
    gap: 4px;
}
.assistant-mode-btn {
    flex: 1;
    padding: 6px 4px;
    border: 1px solid var(--ui-borders-borderDefault);
    border-radius: 999px;
    background: transparent;
    color: var(--ui-text-secondaryText);
    font-size: var(--text-xs, 12px);
    font-weight: 700;
    cursor: pointer;
}
.assistant-mode-btn.is-selected {
    background: var(--ui-text-linkText);
    border-color: var(--ui-text-linkText);
    color: var(--ui-backgrounds-cardBg);
}

/* Which plan the assistant is reading (AI Chat P1-05). Secondary, not muted,
   text: at 12px the muted grey made "walt" read as "wait" (Stephen,
   2026-10-17). The plan name is quoted and bold. */
.assistant-plan-line {
    padding: 6px 16px;
    font-size: var(--text-xs, 12px);
    line-height: 1.4;
    color: var(--ui-text-secondaryText);
    background: var(--ui-backgrounds-panelBg);
    border-bottom: 1px solid var(--ui-borders-borderDefault);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.assistant-plan-name {
    font-weight: 600;
    color: var(--ui-text-primaryText);
}
/* The header's icon buttons (Past chats, New chat, Close) sit on the dark header, so they take its own text colour and
   a light wash on hover (Stephen 2026-10-24: they were dark grey on the dark header). */
.assistant-newchat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--ui-main-headerText, var(--color-ui-header-text));
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.assistant-newchat-btn:hover {
    background: rgba(var(--color-ui-header-text-rgb), 0.16);
    color: var(--ui-main-headerText, var(--color-ui-header-text));
}
.assistant-newchat-btn:focus-visible {
    outline: 2px solid var(--ui-borders-borderFocus);
    outline-offset: 1px;
}
.assistant-close-btn {
    border: none;
    background: transparent;
    color: var(--ui-main-headerText, var(--color-ui-header-text));
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.assistant-close-btn:hover { background: rgba(var(--color-ui-header-text-rgb), 0.16); }

/* ---- Messages area ---- */
.assistant-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
}
.assistant-messages::-webkit-scrollbar { width: 8px; }
.assistant-messages::-webkit-scrollbar-track { background: var(--ui-sliders-scrollbars-scrollbarTrackBg); }
.assistant-messages::-webkit-scrollbar-thumb {
    background: var(--ui-sliders-scrollbars-scrollbarThumbBg);
    border-radius: 4px;
}

.assistant-msg {
    max-width: 92%;
    padding: 10px 13px;
    border-radius: 12px;
    font-size: var(--text-small, 14px);
    line-height: 1.55;
    color: var(--ui-text-primaryText);
    overflow-wrap: break-word;
}
.assistant-msg-user {
    align-self: flex-end;
    background: var(--ui-backgrounds-selectedBg);
    border: 1px solid var(--ui-borders-borderLight);
    border-bottom-right-radius: 4px;
}
.assistant-msg-bot {
    align-self: flex-start;
    background: var(--ui-backgrounds-cardBg);
    border: 1px solid var(--ui-borders-borderDefault);
    border-bottom-left-radius: 4px;
}
.assistant-msg-bot p { margin: 0 0 8px; }
.assistant-msg-bot p:last-child { margin-bottom: 0; }
.assistant-msg-bot ul { margin: 4px 0 8px; padding-left: 18px; }
.assistant-msg-bot li { margin-bottom: 3px; }
.assistant-msg-bot a { color: var(--ui-text-linkText); }

/* Streaming caret */
.assistant-msg-bot.assistant-streaming::after {
    content: '▍';
    color: var(--ui-text-mutedText);
    animation: assistant-blink 1s steps(1) infinite;
}
@keyframes assistant-blink { 50% { opacity: 0; } }

/* Tool progress line ("Reviewing your plan") */
.assistant-progress {
    align-self: flex-start;
    font-size: var(--text-xs, 12px);
    font-style: italic;
    color: var(--ui-text-mutedText);
    padding: 2px 6px;
}

/* "Read more" cards (AI Chat P1-08): one per help section the server
   validated; they open the help page in a new tab. The old Sources chips
   are gone (the Sources line is an audit record now). */
.assistant-readmore {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--ui-borders-borderLight);
}
.assistant-msg-bot a.assistant-readmore-card {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border: 1px solid var(--ui-borders-borderDefault);
    border-radius: 8px;
    background: var(--ui-backgrounds-panelBg);
    color: var(--ui-text-linkText);
    text-decoration: none;
}
.assistant-msg-bot a.assistant-readmore-card:hover { background: var(--ui-backgrounds-hoverBg); }
.assistant-msg-bot a.assistant-readmore-card:focus-visible {
    outline: 2px solid var(--ui-borders-borderFocus);
    outline-offset: 2px;
}
.assistant-readmore-label {
    font-size: var(--text-small, 14px);
    font-weight: 600;
    line-height: 1.35;
}
.assistant-readmore-detail {
    color: var(--ui-text-mutedText);
    line-height: 1.35;
}

/* ---- Review card for plan changes (AI Chat P3-04, assistantChangeCard.js) ----
   Sizes come from the text tokens and t- classes on the markup; the selected
   button is the house contrast pair (link colour on card background). */
.assistant-change-card {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--ui-borders-borderDefault);
    border-left: 3px solid var(--ui-text-linkText);
    border-radius: 10px;
    background: var(--ui-backgrounds-cardBg);
    color: var(--ui-text-primaryText);
}
.assistant-change-card.is-applied,
.assistant-change-card.is-partial { border-left-color: var(--color-semantic-success); }
.assistant-change-card.is-undone,
.assistant-change-card.is-undone-partial,
.assistant-change-card.is-declined,
.assistant-change-card.is-failed { border-left-color: var(--ui-borders-borderDefault); }
.assistant-change-head {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.assistant-change-title {
    font-size: var(--text-small, 14px);
    font-weight: 700;
    line-height: 1.35;
}
.assistant-change-rows {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.assistant-change-row {
    padding: 8px 10px;
    border: 1px solid var(--ui-borders-borderLight);
    border-radius: 8px;
    background: var(--ui-backgrounds-panelBg);
}
.assistant-change-row.is-off { opacity: 0.6; }
.assistant-change-row.is-info {
    background: transparent;
    border-style: dashed;
}
.assistant-change-top {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.assistant-change-check {
    width: 16px;
    height: 16px;
    margin: 0;
    flex: none;
    accent-color: var(--ui-text-linkText);
}
.assistant-change-body { padding-left: 24px; }
.assistant-change-label {
    font-size: var(--text-small, 14px);
    font-weight: 600;
    line-height: 1.35;
}
.assistant-change-values {
    margin-top: 2px;
    font-size: var(--text-small, 14px);
    line-height: 1.4;
    color: var(--ui-text-secondaryText);
}
.assistant-change-to {
    font-weight: 700;
    color: var(--ui-text-primaryText);
}
.assistant-change-sub,
.assistant-change-why { margin-top: 2px; }
/* Full plan editing card (assistantEditCard.js, fulledit 2.3): area headers, values the card asks for, where to look. */
.assistant-change-group {
    margin-top: 4px;
    padding: 0 2px;
    color: var(--ui-text-secondaryText);
}
.assistant-change-group:first-child { margin-top: 0; }
.assistant-change-need {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.assistant-change-input {
    max-width: 240px;
    padding: 6px 8px;
    border: 1px solid var(--ui-borders-borderDefault);
    border-radius: 6px;
    background: var(--ui-backgrounds-cardBg);
    color: var(--ui-text-primaryText);
    font-size: var(--text-small, 14px);
}
.assistant-change-input:focus-visible {
    outline: 2px solid var(--ui-text-linkText);
    outline-offset: 1px;
}
.assistant-change-where { color: var(--ui-text-secondaryText); }
.assistant-change-confirm { margin-top: 6px; }
.assistant-change-goto {
    margin-top: 4px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--ui-text-linkText);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
}
.assistant-change-goto:focus-visible {
    outline: 2px solid var(--ui-text-linkText);
    outline-offset: 2px;
}
.assistant-change-left,
.assistant-change-headline {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--ui-borders-borderLight);
}
.assistant-change-text,
.assistant-change-micro { margin: 0; }
.assistant-change-notice,
.assistant-change-upgrade {
    margin: 0;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(var(--color-blue-6-rgb), 0.08);
}
.assistant-change-upgrade {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}
.assistant-change-upgrade-title {
    font-size: var(--text-small, 14px);
    font-weight: 700;
}
.assistant-change-error {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(var(--color-semantic-danger-rgb), 0.35);
    background: rgba(var(--color-semantic-danger-rgb), 0.08);
    color: var(--ui-text-primaryText);
}
.assistant-change-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.assistant-change-btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--ui-borders-borderDefault);
    border-radius: 8px;
    background: transparent;
    color: var(--ui-text-primaryText);
    font-size: var(--text-small, 14px);
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
}
.assistant-change-btn[hidden],
.assistant-change-actions[hidden],
.assistant-change-left[hidden] { display: none; }
.assistant-change-btn:hover:not(:disabled) { background: var(--ui-backgrounds-hoverBg); }
.assistant-change-btn-primary {
    border-color: var(--ui-text-linkText);
    background: var(--ui-text-linkText);
    color: var(--ui-backgrounds-cardBg);
}
.assistant-change-btn-primary:hover:not(:disabled) {
    border-color: var(--ui-main-linkHover);
    background: var(--ui-main-linkHover);
}
.assistant-change-btn:disabled {
    opacity: 0.5;
    cursor: default;
}
.assistant-change-btn:focus-visible,
.assistant-change-check:focus-visible {
    outline: 2px solid var(--ui-borders-borderFocus);
    outline-offset: 2px;
}

/* Feedback thumbs row (under an assistant answer) */
.assistant-feedback {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    margin-top: -6px;
    padding-left: 4px;
}
.assistant-feedback-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--ui-text-mutedText);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: color 0.15s ease, background 0.15s ease;
}
.assistant-feedback-btn:hover {
    background: var(--ui-backgrounds-hoverBg);
    color: var(--ui-text-secondaryText);
}
.assistant-feedback-btn.selected { color: var(--ui-text-linkText); }
.assistant-feedback-btn:focus-visible {
    outline: 2px solid var(--ui-borders-borderFocus);
    outline-offset: 1px;
}

/* Error bubble */
.assistant-msg-error {
    align-self: stretch;
    background: rgba(var(--color-semantic-danger-rgb), 0.08);
    border: 1px solid rgba(var(--color-semantic-danger-rgb), 0.35);
    color: var(--ui-text-primaryText);
    font-size: var(--text-xs, 12px);
    padding: 9px 12px;
    border-radius: 8px;
}

/* ---- Input area ---- */
.assistant-input-row {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--ui-borders-borderDefault);
    background: var(--ui-backgrounds-panelBg);
}
.assistant-input {
    flex: 1;
    resize: none;
    max-height: 110px;
    padding: 9px 12px;
    font-size: 13.5px;
    font-family: inherit;
    line-height: 1.4;
    border: 1px solid var(--ui-main-inputBorder);
    border-radius: 10px;
    background: var(--ui-backgrounds-cardBg);
    color: var(--ui-text-primaryText);
}
.assistant-input:focus {
    outline: none;
    border-color: var(--ui-borders-borderFocus);
}
.assistant-send-btn {
    align-self: flex-end;
    border: none;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    background: var(--ui-text-linkText);
    color: var(--ui-backgrounds-cardBg);
}
.assistant-send-btn:hover:not(:disabled) { background: var(--ui-main-linkHover); }
.assistant-send-btn:disabled {
    background: var(--ui-main-disabledColor);
    cursor: default;
}

/* ---- "Ask about this" (AI Chat P2-07): entry points on Summary cards and
   Coach suggestions show only while the assistant is on the page
   (body.assistant-ready, set by the drawer); the About chip above the input;
   the place a question was asked from, on its bubble. ---- */
.assistant-ask-btn,
.assistant-ask-link { display: none; }
body.assistant-ready .assistant-ask-link { display: inline; }
body.assistant-ready .assistant-ask-btn {
    display: inline-flex;
    align-items: center;
    margin-left: auto;
    padding: 2px 9px;
    border: 1px solid var(--ui-borders-borderDefault);
    border-radius: 999px;
    background: var(--ui-backgrounds-cardBg);
    color: var(--ui-text-linkText);
    font-size: var(--text-xs, 12px);
    font-weight: 600;
    line-height: 1.5;
    cursor: pointer;
}
body.assistant-ready .assistant-ask-btn:hover { background: var(--ui-backgrounds-hoverBg); }
.assistant-ask-btn:focus-visible {
    outline: 2px solid var(--ui-borders-borderFocus);
    outline-offset: 2px;
}
.assistant-about {
    align-items: center;
    gap: 6px;
    padding: 6px 14px 0;
    background: var(--ui-backgrounds-panelBg);
}
.assistant-about-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.assistant-about-clear {
    border: none;
    background: transparent;
    color: var(--ui-text-secondaryText);
    font-size: var(--text-small, 14px);
    line-height: 1;
    cursor: pointer;
}
.assistant-msg-about {
    margin-bottom: 4px;
    font-weight: 600;
}

/* ---- "Take me there" buttons (AI Chat P2-06): open a place with the app's
   own doors; the line under them says what happened. ---- */
.assistant-goto {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin-top: 10px;
}
.assistant-goto-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--ui-text-linkText);
    border-radius: 8px;
    background: transparent;
    color: var(--ui-text-linkText);
    font-size: var(--text-small, 14px);
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
}
.assistant-goto-btn:hover { background: var(--ui-backgrounds-hoverBg); }
.assistant-goto-btn:focus-visible {
    outline: 2px solid var(--ui-borders-borderFocus);
    outline-offset: 2px;
}
.assistant-goto-plus {
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--ui-text-linkText);
    color: var(--ui-backgrounds-cardBg);
    font-size: var(--text-2xs, 11px);
    font-weight: 700;
}
.assistant-goto-status:empty { display: none; }

/* ---- Suggested questions (AI Chat P2-05): starters in an empty thread, and
   the follow-ups an answer suggests ("Next:"); a chip asks its question. ---- */
.assistant-starters,
.assistant-next {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.assistant-next { margin-top: -4px; }
.assistant-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.assistant-chip {
    padding: 6px 12px;
    border: 1px solid var(--ui-borders-borderDefault);
    border-radius: 999px;
    background: var(--ui-backgrounds-cardBg);
    color: var(--ui-text-linkText);
    font-size: var(--text-small, 14px);
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
}
.assistant-chip:hover { background: var(--ui-backgrounds-hoverBg); }
.assistant-chip:focus-visible {
    outline: 2px solid var(--ui-borders-borderFocus);
    outline-offset: 2px;
}

/* ---- Daily limit (AI Chat P2-03): the Preview counter and the limit card ---- */
.assistant-usage-line {
    padding: 0 14px 4px;
    background: var(--ui-backgrounds-panelBg);
}
.assistant-limit-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--ui-borders-borderDefault);
    background: var(--ui-backgrounds-panelBg);
}
.assistant-limit-text { margin: 0; }

/* ---- Stop, past chats, a note to support (AI Chat P2-09) ---- */
.assistant-send-btn.is-stop {
    background: var(--ui-backgrounds-cardBg);
    color: var(--ui-text-primaryText);
    border: 1px solid var(--ui-borders-borderDefault);
}
.assistant-send-btn.is-stop:hover { background: var(--ui-backgrounds-hoverBg); }
.assistant-stopped { margin-top: 6px; }
.assistant-past {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}
.assistant-past > .assistant-change-btn { align-self: flex-start; margin-top: 4px; }
.assistant-past-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 9px 12px;
    border: 1px solid var(--ui-borders-borderDefault);
    border-radius: 8px;
    background: var(--ui-backgrounds-cardBg);
    color: var(--ui-text-primaryText);
    text-align: left;
    cursor: pointer;
}
.assistant-past-item:hover { background: var(--ui-backgrounds-hoverBg); }
.assistant-past-title {
    font-size: var(--text-small, 14px);
    font-weight: 600;
    line-height: 1.35;
}
.assistant-support {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: -6px;
}
.assistant-support-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.assistant-support-note { flex: none; }

/* ---- Footer disclosure ---- */
.assistant-footer {
    padding: 7px 14px 10px;
    font-size: var(--text-2xs, 11px);
    line-height: 1.4;
    color: var(--ui-text-mutedText);
    background: var(--ui-backgrounds-panelBg);
}

/* ---- Consent view ---- */
.assistant-consent {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    padding: 26px 22px;
    overflow-y: auto;
}
.assistant-consent h3 {
    margin: 0;
    font-size: 17px;
    color: var(--ui-text-primaryText);
}
.assistant-consent p {
    margin: 0;
    font-size: var(--text-small, 14px);
    line-height: 1.6;
    color: var(--ui-text-secondaryText);
}
.assistant-consent-accept {
    margin-top: 6px;
    border: none;
    border-radius: 10px;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    background: var(--ui-text-linkText);
    color: var(--ui-backgrounds-cardBg);
}
.assistant-consent-accept:hover { background: var(--ui-main-linkHover); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .assistant-drawer, .assistant-launch-btn { transition: none; }
    .assistant-msg-bot.assistant-streaming::after { animation: none; }
}
