/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100dvh;
    height: 100vh;
    overflow: hidden;
    font-family: var(--chat-font-family, 'Inter', sans-serif);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: #f5f5f5;
}

/* ===== Chat Container ===== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    height: 100vh;
    background-color: var(--chat-bg, #f5f5f5);
    position: relative;
}

/* ===== Header ===== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    height: 56px;
    background: #fff;
    border-bottom: 1px solid #e5e5e5;
    flex-shrink: 0;
    z-index: 10;
}

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

.avatar-ring {
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent, #4A90D9);
}

.status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: pulse 2s infinite;
}

.header-info {
    display: flex;
    flex-direction: column;
}

.robot-name {
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    line-height: 1.2;
    margin: 0;
}

.robot-status {
    font-size: 12px;
    color: #22c55e;
    font-weight: 500;
}

.rate-trigger {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: #ffc700;
    border-radius: 50%;
    transition: background 0.2s;
}

.rate-trigger:hover {
    background: rgba(255, 199, 0, 0.1);
}

.rate-trigger svg {
    display: block;
}

/* ===== Messages Area ===== */
.messages-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ===== Message Bubbles ===== */
.message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: fadeInUp 0.3s ease-out;
}

.robot-message {
    align-self: flex-start;
}

.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    align-self: flex-end;
}

.avatar-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.message-content {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.robot-message .message-content {
    background: var(--chat-user-bg, #5a839e);
    color: var(--chat-user-fc, white);
    border-bottom-left-radius: 4px;
}

.user-message .message-content {
    background: var(--chat-robot-bg, #d8ecfa);
    color: var(--chat-robot-fc, black);
    border-bottom-right-radius: 4px;
}

/* Special messages (news, wiki, giphy, bible, quotes) */
.special-message .message-content {
    background: #f0f2f5;
    color: #1a1a1a;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
    display: flex;
    gap: 8px;
    max-width: 85%;
    align-self: flex-start;
    animation: fadeInUp 0.3s ease-out;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chat-user-bg, #5a839e);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-user-fc, white);
    border-radius: 50%;
    opacity: 0.6;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ===== Input Bar ===== */
.input-bar {
    padding: 8px 16px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-top: 1px solid #e5e5e5;
    flex-shrink: 0;
}

.input-form {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f0f0f0;
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    padding: 8px 0;
    color: #1a1a1a;
    min-width: 0;
}

.chat-input::placeholder {
    color: #999;
}

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

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--chat-send-btn-bg, #4A90D9);
    color: var(--chat-send-btn-fc, white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.send-btn:hover {
    opacity: 0.9;
}

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

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

/* ===== Error Message ===== */
.error-message .message-content {
    background: #fee2e2;
    color: #991b1b;
}

/* ===== Media in messages ===== */
.message-content img {
    max-width: 100%;
    border-radius: 12px;
    margin: 4px 0;
    display: block;
}

.message-content video {
    max-width: 100%;
    border-radius: 12px;
}

.message-content a {
    color: inherit;
    text-decoration: underline;
}

/* ===== Animations ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ===== Focus styles ===== */
:focus-visible {
    outline: 3px solid #4A90D9;
    outline-offset: 2px;
}

/* ===== Responsive ===== */
@media (min-width: 768px) {
    .chat-container {
        max-width: 600px;
        margin: 0 auto;
        border-left: 1px solid #e5e5e5;
        border-right: 1px solid #e5e5e5;
    }

    .message {
        max-width: 70%;
    }
}

@media (max-width: 375px) {
    .chat-header {
        padding: 8px 12px;
    }

    .messages-area {
        padding: 12px;
        gap: 8px;
    }

    .input-bar {
        padding: 6px 12px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    }
}
