/* Asa chat widget – aligned with Asytra Trace design language */
.asytra-chat-wrap {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

.asytra-chat-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #09adb7 0%, #089da5 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(9, 173, 183, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s ease;
}

.asytra-chat-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(9, 173, 183, 0.45);
}

.asytra-chat-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(9, 173, 183, 0.25);
}

.asytra-chat-btn:active {
    transform: scale(0.98);
}

.asytra-chat-btn--panel-open {
    transform: scale(1.05) rotate(-8deg);
    box-shadow: 0 6px 20px rgba(9, 173, 183, 0.45);
}

.asytra-chat-btn--panel-open:hover {
    transform: scale(1.08) rotate(-8deg);
}

.asytra-chat-btn svg {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.asytra-chat-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 420px;
    max-width: calc(100vw - 48px);
    height: 580px;
    max-height: calc(100vh - 100px);
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 12px;
    box-shadow:
        0 25px 50px -12px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    opacity: 0;
    transform: scale(0.92) translateY(12px);
    transform-origin: bottom right;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
        transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
        visibility 0s linear 0.28s;
}

.asytra-chat-panel.asytra-chat-panel--open {
    opacity: 1;
    transform: scale(1) translateY(0);
    visibility: visible;
    pointer-events: auto;
    transition:
        opacity 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
        transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
        visibility 0s linear 0s;
}

.asytra-chat-panel-header {
    padding: 16px 20px;
    background: linear-gradient(90deg, #09adb7 0%, #089da5 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.asytra-chat-panel-title {
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.01em;
}

.asytra-chat-panel-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s ease, transform 0.2s ease;
}

.asytra-chat-panel-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.asytra-chat-panel-close:active {
    transform: scale(0.95);
}

.asytra-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #f8fafc;
}

.asytra-chat-msg-group {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-self: flex-start;
    max-width: 88%;
}

.asytra-chat-follow-ups {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    animation: asytra-follow-ups-in 0.22s ease-out forwards;
}

.asytra-chat-follow-up-btn {
    padding: 5px 11px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.35;
    font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #475569;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    max-width: 100%;
    white-space: normal;
    text-align: left;
    opacity: 0;
    animation: asytra-follow-up-btn-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.asytra-chat-follow-up-btn:nth-child(1) { animation-delay: 0.04s; }
.asytra-chat-follow-up-btn:nth-child(2) { animation-delay: 0.09s; }
.asytra-chat-follow-up-btn:nth-child(3) { animation-delay: 0.14s; }

.asytra-chat-follow-up-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #089da5;
}

@keyframes asytra-follow-ups-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes asytra-follow-up-btn-in {
    from {
        opacity: 0;
        transform: scale(0.85) translateY(6px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.asytra-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.asytra-chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.04);
    border-radius: 3px;
}

.asytra-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.asytra-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

.asytra-chat-msg {
    max-width: 88%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 15px;
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    box-sizing: border-box;
    height: fit-content;
    min-height: fit-content;
    overflow: visible;
    flex-shrink: 0;
}

.asytra-chat-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #09adb7 0%, #089da5 100%);
    color: #fff;
    border: none;
}

.asytra-chat-msg.assistant {
    align-self: flex-start;
    width: 335px;
    max-width: 100%;
    min-height: 24px;
    height: fit-content;
    overflow: visible;
    box-sizing: border-box;
    background: #ffffff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
}

.asytra-chat-msg.error {
    align-self: flex-start;
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.asytra-chat-msg strong {
    font-weight: 700;
}

.asytra-chat-msg em {
    font-style: italic;
}

.asytra-chat-msg code {
    font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;
    font-size: 0.9em;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.06);
}

.asytra-chat-msg.user code {
    background: rgba(255, 255, 255, 0.25);
}

.asytra-chat-msg a {
    color: #089da5;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.asytra-chat-msg a:hover {
    color: #068a91;
}

.asytra-chat-msg.error a {
    color: #dc2626;
}

/* Rich markdown rendering inside assistant messages */
.asytra-chat-msg > :first-child {
    margin-top: 0;
}

.asytra-chat-msg > :last-child {
    margin-bottom: 0;
}

.asytra-chat-msg p {
    margin: 0 0 10px 0;
}

.asytra-chat-msg h1,
.asytra-chat-msg h2,
.asytra-chat-msg h3,
.asytra-chat-msg h4,
.asytra-chat-msg h5,
.asytra-chat-msg h6 {
    margin: 14px 0 8px 0;
    font-weight: 700;
    line-height: 1.3;
    color: #0f172a;
}

.asytra-chat-msg h1 { font-size: 1.3em; }
.asytra-chat-msg h2 { font-size: 1.18em; }
.asytra-chat-msg h3 { font-size: 1.08em; }
.asytra-chat-msg h4,
.asytra-chat-msg h5,
.asytra-chat-msg h6 { font-size: 1em; }

.asytra-chat-msg ul,
.asytra-chat-msg ol {
    margin: 0 0 10px 0;
    padding-left: 20px;
}

.asytra-chat-msg li {
    margin: 3px 0;
}

.asytra-chat-msg li::marker {
    color: #089da5;
}

.asytra-chat-msg blockquote {
    margin: 0 0 10px 0;
    padding: 4px 0 4px 12px;
    border-left: 3px solid #09adb7;
    color: #475569;
}

.asytra-chat-msg hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 12px 0;
}

.asytra-chat-msg pre {
    margin: 0 0 10px 0;
    padding: 10px 12px;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 8px;
    overflow-x: auto;
}

.asytra-chat-msg pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: 0.85em;
}

.asytra-chat-table-wrap {
    margin: 0 0 10px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.asytra-chat-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.85em;
}

.asytra-chat-table th,
.asytra-chat-table td {
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    vertical-align: top;
}

.asytra-chat-table th:last-child,
.asytra-chat-table td:last-child {
    border-right: none;
}

.asytra-chat-table tbody tr:last-child td {
    border-bottom: none;
}

.asytra-chat-table thead th {
    background: #f1f5f9;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
}

/* Blinking caret while a reply is streaming */
.asytra-chat-streaming > :last-child::after {
    content: "";
    display: inline-block;
    width: 6px;
    height: 1em;
    margin-left: 3px;
    vertical-align: -0.15em;
    background: #09adb7;
    border-radius: 1px;
    animation: asytra-chat-caret-blink 1s steps(2, start) infinite;
}

@keyframes asytra-chat-caret-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.asytra-chat-input-wrap {
    padding: 16px 20px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    align-items: flex-end;
}

.asytra-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    font-weight: 500;
    color: #1a1a1a;
    resize: none;
    min-height: 48px;
    max-height: 120px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.asytra-chat-input::placeholder {
    color: #94a3b8;
    font-weight: 400;
}

.asytra-chat-input:hover {
    border-color: #cbd5e1;
}

.asytra-chat-input:focus {
    outline: none;
    border-color: #09adb7;
    box-shadow: 0 0 0 3px rgba(9, 173, 183, 0.12);
}

.asytra-chat-send {
    padding: 12px 20px;
    background: linear-gradient(90deg, #09adb7 0%, #089da5 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(9, 173, 183, 0.3);
}

.asytra-chat-send:hover:not(:disabled) {
    opacity: 0.95;
    transform: translateY(-1px);
}

.asytra-chat-send:active:not(:disabled) {
    transform: translateY(0);
}

.asytra-chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Skeleton loading: one-line placeholder while waiting for response (not the message bubble) */
.asytra-chat-loading-skeleton {
    align-self: flex-start;
    width: 335px;
    max-width: 100%;
    box-sizing: border-box;
    padding: 12px 16px;
    border-radius: 12px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0;
    min-height: auto;
    height: auto;
}

.asytra-chat-loading-skeleton span {
    display: block;
    height: 14px;
    flex-shrink: 0;
    border-radius: 6px;
    background: linear-gradient(
        90deg,
        #e2e8f0 0%,
        #e2e8f0 40%,
        #f1f5f9 50%,
        #e2e8f0 60%,
        #e2e8f0 100%
    );
    background-size: 200% 100%;
    animation: asytra-skeleton-shimmer 1.2s ease-in-out infinite;
}

.asytra-chat-loading-skeleton span { width: 65%; }

@keyframes asytra-skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Word-by-word reveal animation */
.asytra-chat-word {
    opacity: 0;
    animation: asytra-chat-word-in 0.35s ease forwards;
}

@keyframes asytra-chat-word-in {
    from {
        opacity: 0;
        transform: translateY(2px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Incoming stream tokens */
.asytra-chat-stream-token {
    display: inline;
    animation: asytra-stream-token-in 0.28s ease-out forwards;
}

@keyframes asytra-stream-token-in {
    from {
        opacity: 0;
        transform: translateY(1px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    .asytra-chat-wrap {
        left: 16px;
        right: auto;
        bottom: 16px;
    }

    .asytra-chat-btn {
        width: 52px;
        height: 52px;
    }

    .asytra-chat-panel {
        left: 0;
        right: auto;
        bottom: 64px;
        transform-origin: bottom left;
    }

    .asytra-chat-panel.asytra-chat-panel--open {
        transform: scale(1) translateY(0);
    }
}

@media (max-width: 480px) {
    .asytra-chat-wrap {
        bottom: 16px;
        right: 16px;
    }

    .asytra-chat-panel {
        bottom: 64px;
        right: 0;
        width: calc(100vw - 32px);
        max-width: none;
        height: 70vh;
        border-radius: 16px 16px 0 0;
    }

    .asytra-chat-panel-header {
        padding: 14px 16px;
    }

    .asytra-chat-panel-title {
        font-size: 16px;
    }

    .asytra-chat-messages {
        padding: 16px;
        gap: 12px;
    }

    .asytra-chat-msg {
        padding: 10px 14px;
        font-size: 14px;
    }

    .asytra-chat-follow-up-btn {
        padding: 4px 10px;
        font-size: 11px;
        border-radius: 12px;
    }

    .asytra-chat-input-wrap {
        padding: 12px 16px;
    }

    .asytra-chat-input {
        min-height: 44px;
        font-size: 16px;
    }
}
