/* AI Assistant chat UI */

.page-wrapper:has(.assistant-page-full) {
    padding-top: 60px;
}

.assistant-page-full {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
    max-height: calc(100vh - 60px);
    min-height: calc(100vh - 60px);
    padding: 0 !important;
    margin: 0 !important;
    width: 100%;
    background: var(--ai-chat-canvas, #fff);
}

.assistant-page-full > .ai-chat,
.assistant-page-full .ai-chat {
    flex: 1;
    min-height: 0;
}

.ai-chat {
    /* Neutral chat palette — no brand orange in the thread */
    --ai-chat-canvas: var(--ns-color-bg-light, #f8f9fa);
    --ai-chat-surface: var(--ns-color-white, #ffffff);
    --ai-chat-surface-muted: var(--ns-statement-search-bg, #f5f6f7);
    --ai-chat-border: #e8ebed;
    --ai-chat-border-strong: var(--ns-color-border-medium, #d0d0d0);
    --ai-chat-text: var(--ns-color-blue, #212b36);
    --ai-chat-muted: var(--ns-color-gray, #637381);
    --ai-chat-user-bg: #3d4a59;
    --ai-chat-user-text: #ffffff;
    --ai-chat-user-time: rgba(255, 255, 255, 0.72);
    --ai-chat-assistant-bg: #eef1f4;
    --ai-chat-assistant-text: var(--ns-color-blue, #212b36);
    --ai-chat-avatar-size: 32px;
    --ai-chat-accent: #3d4a59;
    --ai-chat-accent-hover: #212b36;
    --ai-chat-accent-soft: var(--ns-color-blue-secondary, #4f5d71);
    --ai-chat-send-disabled: var(--ns-color-lightgray2, #dbd9d9);
    --ai-chat-column: 768px;
    --ai-chat-confirm: #3d4a59;
    --ai-chat-confirm-hover: #212b36;
    --ai-chat-shadow-sm: 0 1px 3px rgba(33, 43, 54, 0.06);
    --ai-chat-shadow-card: 0 4px 18px rgba(33, 43, 54, 0.07);
    --ai-chat-shadow-card-hover: 0 8px 28px rgba(33, 43, 54, 0.1);
    --ai-chat-user-avatar-bg: #3d4a59;
    --ai-chat-assistant-avatar-bg: #dfe3e8;
    --ai-chat-assistant-avatar-color: #637381;
    --ai-chat-icon-bg: #dfe3e8;
    --ai-chat-icon-color: #637381;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0;
    background: var(--ai-chat-canvas);
    color: var(--ai-chat-text);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
}

/* ── Header ── */
.ai-chat__header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 16px;
    background: var(--ai-chat-surface);
    border-bottom: 1px solid var(--ai-chat-border);
    box-shadow: var(--ai-chat-shadow-sm);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 3;
}

.ai-chat__header-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    letter-spacing: -0.02em;
    color: var(--ai-chat-text);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chat__header-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--ai-chat-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ai-chat__header-btn:hover:not(:disabled) {
    background: var(--ai-chat-surface-muted);
}

.ai-chat__header-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ai-chat__header-btn--placeholder {
    pointer-events: none;
    visibility: hidden;
}

/* ── Thread ── */
.ai-chat__thread-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--ai-chat-canvas);
}

.ai-chat__thread {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.ai-chat__thread-inner {
    max-width: var(--ai-chat-column);
    margin: 0 auto;
    padding: 24px 20px 32px;
    width: 100%;
}

.ai-chat--landing .ai-chat__thread-inner {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: 12px;
    padding-bottom: 12px;
}

.ai-chat__messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Message rows ── */
.ai-chat-msg {
    display: flex;
    width: 100%;
}

.ai-chat-msg--user {
    justify-content: flex-end;
}

.ai-chat-msg--assistant {
    justify-content: flex-start;
}

.ai-chat-msg--continued {
    margin-top: -6px;
}

.ai-chat-msg__inner {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: min(88%, 560px);
}

.ai-chat-msg--user .ai-chat-msg__inner {
    flex-direction: row;
    margin-left: auto;
}

.ai-chat-msg--assistant .ai-chat-msg__inner {
    flex-direction: row;
    margin-right: auto;
}

.ai-chat-msg__avatar,
.ai-chat-msg__avatar-spacer {
    width: var(--ai-chat-avatar-size);
    height: var(--ai-chat-avatar-size);
    flex-shrink: 0;
}

.ai-chat-msg__avatar {
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
}

.ai-chat-msg__avatar--user {
    background: var(--ai-chat-user-avatar-bg);
    color: #fff;
    box-shadow: 0 1px 4px rgba(33, 43, 54, 0.18);
}

.ai-chat-msg__avatar--assistant {
    background: var(--ai-chat-assistant-avatar-bg);
    color: var(--ai-chat-assistant-avatar-color);
    font-size: 18px;
}

.ai-chat-msg__content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.ai-chat-msg__body {
    position: relative;
    padding: 10px 14px;
    word-break: break-word;
}

.ai-chat-msg--user .ai-chat-msg__body {
    background: var(--ai-chat-user-bg);
    color: var(--ai-chat-user-text);
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 1px 4px rgba(33, 43, 54, 0.12);
}

.ai-chat-msg--assistant .ai-chat-msg__body {
    background: var(--ai-chat-assistant-bg);
    color: var(--ai-chat-assistant-text);
    border-radius: 16px 16px 16px 4px;
    box-shadow: var(--ai-chat-shadow-sm);
}

.ai-chat-msg--typing .ai-chat-msg__body {
    padding: 12px 16px;
}

.ai-chat-msg__text {
    font-size: 15px;
    line-height: 1.6;
    word-break: break-word;
}

.ai-chat-msg--user .ai-chat-msg__text {
    color: var(--ai-chat-user-text);
}

.ai-chat-msg--assistant .ai-chat-msg__text {
    color: var(--ai-chat-assistant-text);
}

.ai-chat-msg__text ul,
.ai-chat-msg__text ol {
    margin: 0 0 6px;
    padding-left: 1.25em;
}

.ai-chat-msg__text li {
    margin: 0 0 2px;
}

.ai-chat-msg__text li:last-child {
    margin-bottom: 0;
}

.ai-chat-msg__text p {
    margin: 0 0 6px;
}

.ai-chat-msg__text p:last-child,
.ai-chat-msg__text ul:last-child,
.ai-chat-msg__text ol:last-child {
    margin-bottom: 0;
}

.ai-chat-msg__time {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    line-height: 1.2;
}

.ai-chat-msg--user .ai-chat-msg__time {
    text-align: right;
    color: var(--ai-chat-user-time);
}

.ai-chat-msg--assistant .ai-chat-msg__time {
    color: var(--ai-chat-muted);
}

.ai-chat-msg--error .ai-chat-msg__body {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 16px 16px 16px 4px;
    color: #991b1b;
}

.ai-chat-msg--error .ai-chat-msg__text {
    color: #991b1b;
}

.ai-chat-msg__retry {
    margin-top: 10px;
    padding: 0;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 600;
    color: inherit;
    opacity: 0.9;
    cursor: pointer;
    text-decoration: underline;
}

.ai-chat-msg__retry:hover {
    opacity: 1;
}

.ai-chat-msg__followup {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(88%, 560px);
    margin: -8px 0 0 calc(var(--ai-chat-avatar-size) + 10px);
}

/* ── Landing ── */
.ai-chat__landing {
    text-align: center;
    padding: 20px 20px 28px;
    background: var(--ai-chat-surface);
    border: 1px solid var(--ai-chat-border);
    border-radius: 12px;
    box-shadow: var(--ai-chat-shadow-card);
}

.ai-chat__landing-eyebrow {
    margin: 0 0 12px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ai-chat-muted);
}

.ai-chat__landing-title {
    margin: 0 0 12px;
    font-size: clamp(1.625rem, 3.5vw, 2.125rem);
    font-weight: 600;
    letter-spacing: -0.035em;
    line-height: 1.15;
    color: var(--ai-chat-text);
}

.ai-chat__landing-sub {
    margin: 0 auto 20px;
    max-width: 540px;
    font-size: 15px;
    line-height: 1.65;
    color: var(--ai-chat-muted);
}

.ai-chat__capabilities {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 28px;
}

.ai-chat__cap {
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--ai-chat-border);
    background: var(--ai-chat-surface-muted);
    font-size: 12px;
    font-weight: 600;
    color: var(--ai-chat-accent-soft);
    letter-spacing: 0.01em;
}

.ai-chat__suggestions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 24px;
    text-align: left;
}

.ai-chat__suggestion {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 16px;
    border: 1px solid var(--ai-chat-border);
    border-radius: 10px;
    background: var(--ai-chat-surface);
    box-shadow: var(--ai-chat-shadow-sm);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
    text-align: left;
    min-height: 118px;
}

.ai-chat__suggestion:hover:not(:disabled) {
    border-color: var(--ai-chat-border-strong);
    box-shadow: var(--ai-chat-shadow-card-hover);
    transform: translateY(-2px);
}

.ai-chat__suggestion:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.ai-chat__suggestion-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--ai-chat-icon-bg);
    color: var(--ai-chat-icon-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.ai-chat__suggestion-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ai-chat__suggestion-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--ai-chat-text);
    line-height: 1.3;
}

.ai-chat__suggestion-desc {
    font-size: 13px;
    color: var(--ai-chat-muted);
    line-height: 1.4;
}

.ai-chat__landing-note {
    margin: 0 0 8px;
    font-size: 12px;
    color: var(--ai-chat-muted);
}

.ai-chat__import-link {
    font-size: 13px;
    font-weight: 600;
    color: var(--ns-color-secondary, #3068a4);
    text-decoration: none;
}

.ai-chat__import-link:hover {
    color: var(--ns-color-secondary, #3068a4);
    text-decoration: underline;
}

/* ── Typing indicator ── */
.ai-chat-msg__thinking {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    color: var(--ai-chat-muted);
}

.ai-chat-msg__typing-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.ai-chat-msg__typing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--ai-chat-muted);
    opacity: 0.55;
    animation: ai-chat-bounce 1.2s infinite ease-in-out;
}

.ai-chat-msg__typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat-msg__typing-dots span:nth-child(3) { animation-delay: 0.3s; }

/* ── Composer ── */
.ai-chat__composer-wrap {
    flex-shrink: 0;
    padding: 8px 20px 16px;
    background: transparent;
    border-top: none;
    box-shadow: none;
}

.ai-chat__composer-inner {
    max-width: var(--ai-chat-column);
    margin: 0 auto;
    width: 100%;
}

.ai-chat__composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px 8px 18px;
    background: var(--ai-chat-surface);
    border: 1px solid var(--ai-chat-border);
    border-radius: 14px;
    box-shadow: var(--ai-chat-shadow-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ai-chat__composer:focus-within {
    border-color: var(--ai-chat-border-strong);
    box-shadow: 0 0 0 3px rgba(33, 43, 54, 0.08), var(--ai-chat-shadow-sm);
}

.ai-chat__input {
    flex: 1;
    width: 100%;
    resize: none;
    border: none !important;
    background: transparent !important;
    padding: 10px 0;
    font-size: 16px;
    line-height: 1.5;
    max-height: 200px;
    min-height: 24px;
    color: var(--ai-chat-text);
    font-family: inherit;
    box-shadow: none !important;
    outline: none !important;
}

.ai-chat__input:focus {
    outline: none !important;
    box-shadow: none !important;
}

.ai-chat__input::placeholder {
    color: var(--ai-chat-muted);
}

.ai-chat__input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.ai-chat__send {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    border: none;
    border-radius: 8px;
    background: var(--ai-chat-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.ai-chat__send:hover:not(:disabled) {
    background: var(--ai-chat-accent-hover);
}

.ai-chat__send:active:not(:disabled) {
    transform: scale(0.96);
}

.ai-chat__send:disabled {
    background: var(--ai-chat-send-disabled);
    color: #fff;
    cursor: not-allowed;
}

.ai-chat__disclaimer {
    margin: 8px 0 0;
    text-align: center;
    font-size: 11px;
    line-height: 1.4;
    color: var(--ai-chat-muted);
}

/* ── Interactive actions ── */
.ai-chat__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
}

.ai-chat__action {
    min-height: 38px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--ai-chat-border);
    background: var(--ai-chat-surface);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    box-shadow: var(--ai-chat-shadow-sm);
}

.ai-chat__action--primary {
    background: var(--ai-chat-confirm);
    border-color: var(--ai-chat-confirm);
    color: #fff;
}

.ai-chat__action--primary:hover:not(:disabled) {
    background: var(--ai-chat-confirm-hover);
    border-color: var(--ai-chat-confirm-hover);
}

.ai-chat__action--muted {
    background: transparent;
    color: var(--ai-chat-muted);
}

.ai-chat__action--neutral {
    background: var(--ai-chat-surface-muted);
}

.ai-chat__action:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.ai-chat__action-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: ai-chat-spin 0.6s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
}

.ai-chat__status-badge {
    margin: 0;
    font-size: 12px;
    color: var(--ai-chat-muted);
    font-weight: 500;
}

/* ── Scroll FAB & skeleton ── */
.ai-chat__scroll-fab {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 16px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--ai-chat-border);
    background: var(--ai-chat-surface);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    color: var(--ai-chat-text);
}

.ai-chat__skeleton {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ai-chat__skeleton-line {
    height: 48px;
    border-radius: 16px;
    background: linear-gradient(90deg, var(--ai-chat-assistant-bg, #eef1f4) 25%, #e3e7eb 50%, var(--ai-chat-assistant-bg, #eef1f4) 75%);
    background-size: 200% 100%;
    animation: ai-chat-shimmer 1.2s infinite;
    max-width: 68%;
}

.ai-chat__skeleton-line--user {
    margin-left: auto;
    max-width: 46%;
    border-radius: 16px 16px 4px 16px;
    background: linear-gradient(90deg, #d5dbe2 25%, #c5ccd4 50%, #d5dbe2 75%);
    background-size: 200% 100%;
}

@keyframes ai-chat-spin {
    to { transform: rotate(360deg); }
}

@keyframes ai-chat-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
    40% { transform: translateY(-4px); opacity: 1; }
}

@keyframes ai-chat-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── RTL ── */
[dir="rtl"] .ai-chat-msg--user .ai-chat-msg__inner {
    margin-left: 0;
    margin-right: auto;
}

[dir="rtl"] .ai-chat-msg--assistant .ai-chat-msg__inner {
    margin-right: 0;
    margin-left: auto;
}

[dir="rtl"] .ai-chat-msg--user .ai-chat-msg__body {
    border-radius: 16px 16px 16px 4px;
}

[dir="rtl"] .ai-chat-msg--assistant .ai-chat-msg__body {
    border-radius: 16px 16px 4px 16px;
}

[dir="rtl"] .ai-chat-msg__followup {
    margin-left: 0;
    margin-right: calc(var(--ai-chat-avatar-size) + 10px);
}

[dir="rtl"] .ai-chat-msg--user .ai-chat-msg__time {
    text-align: left;
}

[dir="rtl"] .ai-chat__suggestions,
[dir="rtl"] .ai-chat__suggestion {
    text-align: right;
}

/* ── Dark theme (ERP toggle) ── */
body[data-theme=dark] .ai-chat {
    --ai-chat-canvas: #212121;
    --ai-chat-surface: #2f2f2f;
    --ai-chat-border: #424242;
    --ai-chat-text: #ececec;
    --ai-chat-muted: #b4b4b4;
    --ai-chat-user-bg: #4a5568;
    --ai-chat-user-text: #ffffff;
    --ai-chat-user-avatar-bg: #4a5568;
    --ai-chat-assistant-bg: #3a3a3a;
    --ai-chat-assistant-text: #ececec;
    --ai-chat-assistant-avatar-bg: #4a4a4a;
    --ai-chat-assistant-avatar-color: #c8c8c8;
    --ai-chat-icon-bg: #4a4a4a;
    --ai-chat-icon-color: #c8c8c8;
    --ai-chat-accent: #6b7280;
    --ai-chat-accent-hover: #9ca3af;
    --ai-chat-confirm: #6b7280;
    --ai-chat-confirm-hover: #9ca3af;
    --ai-chat-send-disabled: #565656;
}

body[data-theme=dark] .ai-chat__header {
    background: rgba(33, 33, 33, 0.9);
}

body[data-theme=dark] .ai-chat__header-btn:hover:not(:disabled) {
    background: #303030;
}

body[data-theme=dark] .ai-chat__suggestion-icon {
    background: var(--ai-chat-icon-bg);
    color: var(--ai-chat-icon-color);
}

body[data-theme=dark] .ai-chat__suggestion:hover:not(:disabled) {
    background: #333;
}

/* ── Responsive ── */
@media (max-width: 860px) {
    .ai-chat {
        --ai-chat-column: 100%;
    }

    .ai-chat__thread-inner,
    .ai-chat__composer-inner {
        padding-left: 16px;
        padding-right: 16px;
    }
}

@media (max-width: 768px) {
    .ai-chat__suggestions {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .ai-chat-msg__inner {
        max-width: 94%;
    }

    .ai-chat-msg__followup {
        max-width: 94%;
    }

    .ai-chat__composer-wrap {
        padding-left: 12px;
        padding-right: 12px;
    }
}
