* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #007a3d;
    --primary-dark: #005a2d;
    --primary-light: #e8f5ee;
    --accent: #f7a800;
    --bg: #f0f2f5;
    --surface: #ffffff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --user-bubble: #007a3d;
    --bot-bubble: #ffffff;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #007a3d 0%, #00a651 100%);
    color: var(--text);
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.chat-shell {
    width: 100%;
    max-width: 720px;
    height: min(92vh, 880px);
    background: var(--surface);
    border-radius: 18px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ========= HEADER ========= */
.chat-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: var(--primary);
    color: white;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--primary-dark);
    font-weight: 700;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-info {
    flex: 1;
}

.header-info h1 {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.2;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.85;
    margin-top: 2px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6);
    animation: pulse 1.6s infinite;
}

@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
    70%  { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.reset-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.reset-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ========= MESSAGES ========= */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    max-width: 320px;
    padding: 24px;
}

.bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14.5px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
    animation: bubble-in 0.2s ease-out;
}

@keyframes bubble-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.bubble.user {
    align-self: flex-end;
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

.bubble.bot {
    align-self: flex-start;
    background: var(--bot-bubble);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.bubble.error {
    align-self: flex-start;
    background: #fee2e2;
    color: #991b1b;
    border-bottom-left-radius: 4px;
    font-size: 13px;
}

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

.bubble.user a { color: #fff8dc; }

.meta {
    font-size: 10.5px;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.bubble.user + .meta { align-self: flex-end; }
.bubble.bot + .meta,
.bubble.error + .meta { align-self: flex-start; }

/* Typing indicator */
.typing {
    align-self: flex-start;
    background: var(--bot-bubble);
    padding: 12px 16px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 4px;
}

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

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

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ========= COMPOSER ========= */
.composer {
    padding: 12px 16px 14px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

#chatForm {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg);
    border-radius: 22px;
    padding: 6px 6px 6px 14px;
}

#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 14.5px;
    line-height: 1.45;
    color: var(--text);
    padding: 8px 0;
    max-height: 140px;
}

#sendBtn {
    background: var(--primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.1s ease;
    flex-shrink: 0;
}

#sendBtn:hover:not(:disabled) {
    background: var(--primary-dark);
}

#sendBtn:active:not(:disabled) {
    transform: scale(0.95);
}

#sendBtn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.session-info {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}

/* ========= SCROLLBAR ========= */
.messages::-webkit-scrollbar {
    width: 6px;
}

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

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

/* ========= RESPONSIVE ========= */
@media (max-width: 600px) {
    body { padding: 0; }
    .chat-shell {
        height: 100vh;
        border-radius: 0;
        max-width: 100%;
    }
}
