/* ===== Chat Container ===== */
.chat-container-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    border-radius: 17px;
    padding: 1px;
    background: linear-gradient(135deg, #6366f1, #818cf8, #a78bfa, #6366f1);
    background-size: 300% 300%;
    animation: border-rotate 8s ease infinite;
}

@keyframes border-rotate {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.chat-container-wrapper::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 18px;
    background: inherit;
    background-size: inherit;
    animation: inherit;
    filter: blur(16px);
    opacity: 0.4;
    z-index: -1;
    transition: opacity 0.3s;
}

.chat-container-wrapper:hover::before {
    opacity: 0.6;
}

.chat-container {
    text-align: left;
    background: #1a1b26;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    height: 62vh;
    min-height: 420px;
    max-height: 700px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transition: box-shadow 0.3s ease;
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===== Chat Header ===== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 16px;
    border-bottom: 1px solid #2a2b3a;
    background: #1e1f2e;
    border-radius: 16px 16px 0 0;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    flex-shrink: 0;
    animation: status-pulse 2.5s ease-in-out infinite;
}

@keyframes status-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
    50%       { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0); }
}

.chat-header-title {
    font-size: 13px;
    font-weight: 600;
    color: #94a3b8;
    letter-spacing: 0.02em;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

.chat-clear-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #3d4460;
    padding: 5px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
}

.chat-clear-btn:hover {
    color: #94a3b8;
    background: #252736;
}

.chat-clear-btn svg {
    width: 15px;
    height: 15px;
}

.chat-container:hover {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

/* ===== Messages Area ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #2a2b3a;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #3a3b4a;
}

/* ===== Message Column Wrapper ===== */
.chat-msg-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1;
}

.chat-assistant .chat-msg-col {
    align-items: flex-start;
}

.chat-user .chat-msg-col {
    align-items: flex-end;
}

/* ===== Copy Button ===== */
.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: 1px solid #2a2b3a;
    border-radius: 6px;
    padding: 3px 8px;
    cursor: pointer;
    color: #475569;
    font-size: 11px;
    font-family: inherit;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, border-color 0.15s, background 0.15s;
    align-self: flex-start;
    margin-top: 2px;
}

.copy-btn svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.chat-assistant:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    color: #94a3b8;
    border-color: #3a3b4a;
    background: #252736;
}

.copy-btn.copied {
    color: #22c55e;
    border-color: #22c55e;
    opacity: 1;
}

/* ===== Message Bubbles ===== */
.chat-bubble {
    display: flex;
    gap: 10px;
    max-width: 85%;
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    animation: bubble-fade-up 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes bubble-fade-up {
    0% {
        opacity: 0;
        transform: translateY(16px) scale(0.95);
        filter: blur(2px);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

.chat-user {
    align-self: flex-end;
    flex-direction: row-reverse;
    animation-name: bubble-user-in;
}

@keyframes bubble-user-in {
    0% {
        opacity: 0;
        transform: translateY(10px) translateX(20px) scale(0.93);
        filter: blur(2px);
    }
    100% {
        opacity: 1;
        transform: translateY(0) translateX(0) scale(1);
        filter: blur(0);
    }
}

.chat-assistant {
    align-self: flex-start;
    animation-name: bubble-assistant-in;
}

@keyframes bubble-assistant-in {
    0% {
        opacity: 0;
        transform: translateY(10px) translateX(-20px) scale(0.93);
        filter: blur(2px);
    }
    100% {
        opacity: 1;
        transform: translateY(0) translateX(0) scale(1);
        filter: blur(0);
    }
}

/* Welcome message: delayed fade-in + periodic nudge */
.chat-welcome {
    animation-delay: 1.2s;
    animation-duration: 0.7s;
}

.chat-welcome.nudge {
    animation: welcome-nudge 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes welcome-nudge {
    0%   { transform: translateY(0); }
    30%  { transform: translateY(-6px); }
    50%  { transform: translateY(-3px); }
    70%  { transform: translateY(-5px); }
    100% { transform: translateY(0); }
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #252736, #2a2d40);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.chat-body {
    padding: 12px 16px;
    border-radius: 14px;
    line-height: 1.65;
    font-size: 14.5px;
    letter-spacing: 0.01em;
    word-break: break-word;
    transition: background 0.2s ease;
    font-weight: 400;
}

.chat-user .chat-body {
    background: linear-gradient(135deg, #5865F2, #4f46e5);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 12px rgba(88, 101, 242, 0.25);
    font-weight: 500;
    letter-spacing: 0.012em;
}

.chat-assistant .chat-body {
    background: #252736;
    color: #e2e8f0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Markdown inside bot messages */
.chat-assistant .chat-body h1,
.chat-assistant .chat-body h2,
.chat-assistant .chat-body h3 {
    font-size: 15px;
    font-weight: 700;
    margin: 12px 0 6px;
    color: #e2e8f0;
}

.chat-assistant .chat-body h1:first-child,
.chat-assistant .chat-body h2:first-child,
.chat-assistant .chat-body h3:first-child {
    margin-top: 0;
}

.chat-assistant .chat-body p {
    margin: 0 0 8px;
}

.chat-assistant .chat-body p:last-child {
    margin-bottom: 0;
}

.chat-assistant .chat-body ul,
.chat-assistant .chat-body ol {
    margin: 4px 0 8px;
    padding-left: 20px;
}

.chat-assistant .chat-body li {
    margin-bottom: 4px;
}

.chat-assistant .chat-body code {
    background: #1a1b26;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.chat-assistant .chat-body pre {
    background: #1a1b26;
    border: 1px solid #2a2b3a;
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.chat-assistant .chat-body pre code {
    background: none;
    padding: 0;
    font-size: 13px;
}

.chat-assistant .chat-body a {
    color: #818cf8;
    text-decoration: none;
    transition: color 0.15s;
}

.chat-assistant .chat-body a:hover {
    color: #a5b4fc;
    text-decoration: underline;
}

.chat-assistant .chat-body strong {
    color: #f1f5f9;
}

/* ===== System Messages ===== */
.chat-system {
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
    padding: 8px 16px;
    opacity: 0;
    animation: fade-in 0.3s ease forwards;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== Typing Indicator ===== */
.typing-dots {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    height: 20px;
    padding: 2px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #818cf8;
    opacity: 0.3;
    animation: typing-pulse 1.4s infinite ease-in-out;
}

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

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

@keyframes typing-pulse {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.3;
    }
    40% {
        transform: scale(1.1);
        opacity: 1;
    }
}

/* ===== Starter Chips (rotating carousel below chat) ===== */
.chat-chips-track {
    max-width: 1200px;
    margin: 12px auto 0;
    overflow: hidden;
    mask-image: linear-gradient(to right, transparent 0%, black 4%, black 96%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, transparent 0%, black 4%, black 96%, transparent 100%);
    transition: opacity 0.4s ease;
}

.chips-row {
    display: flex;
    gap: 10px;
    white-space: nowrap;
    will-change: transform;
}

.chip {
    padding: 9px 16px;
    background: #252736;
    border: 1px solid #2a2b3a;
    border-radius: 20px;
    color: #e2e8f0;
    font-size: 13px;
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 500;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: translateX(30px);
    animation: chip-slide-in 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.chip:hover {
    border-color: #5865F2;
    background: #2a2d40;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(88, 101, 242, 0.15);
}

.chip:active {
    transform: translateY(0) scale(0.97);
}

@keyframes chip-slide-in {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes chip-slide-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(-30px);
    }
}

/* ===== Input Bar ===== */
.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #2a2b3a;
    background: #1a1b26;
    border-radius: 0 0 16px 16px;
}

.chat-input-bar textarea {
    flex: 1;
    background: #252736;
    border: 1px solid #2a2b3a;
    border-radius: 10px;
    padding: 10px 14px;
    color: #e2e8f0;
    font-size: 14.5px;
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 400;
    letter-spacing: 0.01em;
    resize: none;
    outline: none;
    max-height: 96px;
    line-height: 1.55;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-bar textarea::placeholder {
    color: #64748b;
}

.chat-input-bar textarea:focus {
    border-color: #5865F2;
    box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.12);
}

.chat-input-bar textarea:disabled {
    opacity: 0.5;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: #5865F2;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.chat-send-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(255,255,255,0.15) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.2s;
}

.chat-send-btn:hover:not(:disabled) {
    background: #4f46e5;
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(88, 101, 242, 0.35);
}

.chat-send-btn:hover:not(:disabled)::after {
    opacity: 1;
}

.chat-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chat-send-btn .icon-send,
.chat-send-btn .icon-stop {
    width: 20px;
    height: 20px;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.chat-send-btn .icon-stop {
    display: none;
}

.chat-send-btn.streaming .icon-send {
    display: none;
}

.chat-send-btn.streaming .icon-stop {
    display: block;
}

.chat-send-btn.streaming {
    background: #ef4444;
    animation: none;
}

.chat-send-btn.streaming:hover:not(:disabled) {
    background: #dc2626;
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.35);
    transform: scale(1.05);
}

.chat-send-btn:hover:not(:disabled) .icon-send {
    transform: translate(1px, -1px);
}

/* ===== Input hint ===== */
.chat-input-hint {
    font-size: 11px;
    color: #3d4460;
    padding: 0 16px 10px;
    background: #1a1b26;
    text-align: right;
    display: none;
    border-radius: 0 0 16px 16px;
}

.chat-input-hint.visible {
    display: block;
}

.chat-input-hint kbd {
    font-size: 10px;
    background: #252736;
    border: 1px solid #2a2b3a;
    border-radius: 3px;
    padding: 1px 4px;
    font-family: inherit;
    color: #64748b;
}

/* ===== Tagline below chat ===== */
.chat-tagline {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: #64748b;
    letter-spacing: 0.02em;
}

/* ===== Download buttons below chat ===== */
.hero-download {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 32px;
    flex-wrap: wrap;
}

/* ===== Streaming text cursor ===== */
.chat-body.streaming::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: 16px;
    background: #818cf8;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cursor-blink 0.8s infinite;
}

@keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .chat-container {
        height: 65vh;
        min-height: 380px;
        border-radius: 12px;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-bubble {
        max-width: 92%;
    }

    .hero-download {
        flex-direction: column;
        align-items: center;
    }
}

@media (max-width: 480px) {
    .chat-container {
        height: 70vh;
        border-radius: 10px;
    }

    .chat-body {
        padding: 10px 12px;
        font-size: 14px;
    }

    .chat-avatar {
        width: 28px;
        height: 28px;
        font-size: 15px;
    }
}
