@font-face {
    font-family: system-ui;
    src: local("Arial");
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: #eef1f5;
    font-family: Tahoma, Arial, sans-serif;
    color: #111827;
}

.chat-shell {
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.chat-card {
    width: 100%;
    max-width: 900px;
    height: min(760px, calc(100vh - 48px));
    background: #ffffff;
    border: 1px solid #d8dde6;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.10);
}

.chat-header {
    padding: 18px 22px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: #ffffff;
}

.chat-header h1 {
    margin: 0 0 4px;
    font-size: 20px;
    font-weight: 800;
}

.chat-header p {
    margin: 0;
    color: #6b7280;
    font-size: 13px;
}

.clear-btn {
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    padding: 9px 13px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.clear-btn:hover {
    background: #f9fafb;
}

.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background:
        radial-gradient(circle at top right, rgba(59, 130, 246, .08), transparent 32%),
        #f9fafb;
}

.empty-state {
    height: 100%;
    min-height: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #6b7280;
}

.empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 22px;
    background: #111827;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    margin-bottom: 18px;
    letter-spacing: 1px;
}

.empty-state h2 {
    margin: 0 0 8px;
    color: #111827;
    font-size: 22px;
}

.empty-state p {
    margin: 0;
    font-size: 14px;
}

.message {
    display: flex;
    margin-bottom: 14px;
}

.message.user {
    justify-content: flex-start;
}

.message.assistant {
    justify-content: flex-end;
}

.bubble {
    max-width: 78%;
    padding: 13px 15px;
    line-height: 1.9;
    font-size: 14px;
    white-space: pre-wrap;
    word-break: break-word;
    border: 1px solid transparent;
}

.message.user .bubble {
    background: #111827;
    color: #ffffff;
    border-radius: 16px 16px 4px 16px;
}

.message.assistant .bubble {
    background: #ffffff;
    color: #111827;
    border-color: #e5e7eb;
    border-radius: 16px 16px 16px 4px;
}

.typing {
    display: none;
    align-items: center;
    gap: 5px;
    padding: 0 24px 12px;
    background: #f9fafb;
}

.typing.active {
    display: flex;
}

.typing span {
    width: 7px;
    height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1s infinite ease-in-out;
}

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

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

@keyframes typing {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: .45;
    }
    40% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

.chat-form {
    display: flex;
    align-items: end;
    gap: 10px;
    padding: 16px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
}

.chat-form textarea {
    flex: 1;
    max-height: 160px;
    min-height: 44px;
    resize: none;
    border: 1px solid #d1d5db;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.7;
    outline: none;
    font-family: inherit;
    border-radius: 12px;
}

.chat-form textarea:focus {
    border-color: #111827;
}

.chat-form button {
    width: 92px;
    height: 44px;
    border: 0;
    background: #111827;
    color: #ffffff;
    cursor: pointer;
    border-radius: 12px;
    font-weight: 700;
}

.chat-form button:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.error-toast {
    margin: 0 24px 12px;
    padding: 12px 14px;
    background: #fff1f2;
    color: #9f1239;
    border: 1px solid #fecdd3;
    font-size: 13px;
    line-height: 1.8;
}

@media (max-width: 640px) {
    .chat-shell {
        padding: 0;
    }

    .chat-card {
        height: 100vh;
        max-width: none;
        border: 0;
    }

    .chat-header {
        padding: 14px;
    }

    .chat-header h1 {
        font-size: 17px;
    }

    .chat-body {
        padding: 16px;
    }

    .bubble {
        max-width: 90%;
    }

    .chat-form {
        padding: 12px;
    }

    .clear-btn {
        padding: 8px 10px;
    }
}

.sources {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed #d1d5db;
    font-size: 12px;
    color: #4b5563;
    white-space: normal;
}

.sources strong {
    display: block;
    margin-bottom: 6px;
    color: #111827;
}

.sources span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin: 0 0 6px 6px;
    padding: 4px 7px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
}

.sources small {
    color: #6b7280;
    direction: ltr;
}
