:root {
    color-scheme: light;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #1f2937;
    background:
        radial-gradient(circle at 12% 12%, rgba(255,255,255,.24), transparent 30%),
        linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
}

button, textarea { font: inherit; }

.chat-shell {
    width: min(100%, 760px);
    height: min(820px, calc(100vh - 40px));
    min-height: 520px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(255,255,255,.5);
    border-radius: 20px;
    box-shadow: 0 24px 70px rgba(17,24,39,.28);
}

.chat-header {
    min-height: 82px;
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 14px 18px;
    color: #fff;
    background: linear-gradient(120deg, var(--chat-primary), var(--chat-secondary));
}

.chat-logo {
    width: 52px;
    height: 52px;
    flex: 0 0 52px;
    object-fit: contain;
    padding: 5px;
    border-radius: 13px;
    background: #fff;
}

.chat-heading { min-width: 0; flex: 1; }
.chat-heading h1 {
    overflow: hidden;
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-heading p {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 4px 0 0;
    font-size: .78rem;
    opacity: .9;
}

.online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #86efac;
    box-shadow: 0 0 0 3px rgba(134,239,172,.2);
}

.new-chat-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 11px;
    color: #fff;
    border: 1px solid rgba(255,255,255,.42);
    border-radius: 10px;
    background: rgba(255,255,255,.12);
    cursor: pointer;
}
.new-chat-button:hover { background: rgba(255,255,255,.22); }
.new-chat-button:focus-visible, #send-message:focus-visible, #chat-input:focus-visible {
    outline: 3px solid rgba(255,255,255,.8);
    outline-offset: 2px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 22px;
    background: #f5f7fa;
    scrollbar-color: #cbd5e1 transparent;
}

.message-row { display: flex; margin-bottom: 12px; }
.assistant-row { justify-content: flex-start; }
.user-row { justify-content: flex-end; }

.message-bubble {
    max-width: min(82%, 580px);
    padding: 11px 14px;
    border-radius: 16px;
    line-height: 1.45;
    overflow-wrap: anywhere;
    box-shadow: 0 1px 2px rgba(15,23,42,.08);
}
.assistant-bubble {
    color: #1f2937;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 5px;
}
.user-bubble {
    color: #fff;
    background: var(--chat-primary);
    border-bottom-right-radius: 5px;
}
.error-bubble { color: #991b1b; background: #fef2f2; border-color: #fecaca; }

.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message-content p { margin: 0 0 .55rem; }
.message-content ul, .message-content ol { margin: .4rem 0; padding-left: 1.25rem; }
.message-content pre, .message-content code {
    font-family: Consolas, "Courier New", monospace;
    white-space: pre-wrap;
}
.message-content a { color: inherit; font-weight: 700; text-decoration: underline; }

.message-time {
    display: block;
    margin-top: 5px;
    font-size: .68rem;
    text-align: right;
    opacity: .65;
}

.typing-bubble { display: inline-flex; gap: 4px; padding: 14px 17px; }
.typing-bubble span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typing 1.2s infinite ease-in-out;
}
.typing-bubble span:nth-child(2) { animation-delay: .15s; }
.typing-bubble span:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }

.chat-error {
    margin: 0;
    padding: 8px 18px;
    color: #991b1b;
    font-size: .8rem;
    text-align: center;
    background: #fef2f2;
    border-top: 1px solid #fecaca;
}

.chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 9px;
    padding: 13px 15px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
}

.captcha-anchor {
    display: flex;
    flex: 0 0 auto;
    justify-content: center;
    min-height: 60px;
    padding: 0 10px 8px;
    overflow: hidden;
    background: #fff;
}

.captcha-anchor[hidden] { display: none; }

#chat-input {
    width: 100%;
    max-height: 130px;
    min-height: 44px;
    resize: none;
    padding: 11px 13px;
    color: #111827;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    background: #f9fafb;
}
#chat-input:focus { border-color: var(--chat-primary); outline-color: var(--chat-primary); background: #fff; }

#send-message {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    padding: 0 0 0 2px;
    color: #fff;
    border: 0;
    border-radius: 12px;
    background: var(--chat-primary);
    cursor: pointer;
}
#send-message:disabled { cursor: wait; opacity: .55; }

.chat-caption {
    padding: 0 15px 10px;
    color: #6b7280;
    font-size: .7rem;
    text-align: center;
    background: #fff;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 640px) {
    body { padding: 0; align-items: stretch; }
    .chat-shell { width: 100%; height: 100vh; min-height: 100vh; border: 0; border-radius: 0; }
    .chat-header { min-height: 72px; padding: 10px 12px; }
    .chat-logo { width: 46px; height: 46px; flex-basis: 46px; }
    .new-chat-label { display: none; }
    .new-chat-button { width: 40px; height: 40px; justify-content: center; padding: 0; font-size: 1.15rem; }
    .chat-messages { padding: 15px 12px; }
    .message-bubble { max-width: 89%; }
    .chat-composer { padding: 10px 10px; }
}
