/* =====================================================
   UN CC:Learn · Children & Climate Change
   AI Learning Coach — UNITAR Brand System
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&family=DM+Serif+Display:ital@0;1&display=swap');

:root {
    --unitar-blue:      #318dde;
    --unitar-blue-dark: #1a6bbf;
    --unitar-blue-deep: #0e4a8a;
    --unitar-blue-pale: #e8f3fc;
    --unitar-blue-mist: #f0f7ff;
    --white:            #ffffff;
    --ink:              #111418;
    --ink-secondary:    #4a5568;
    --ink-tertiary:     #8a9ab0;
    --border:           #dde8f4;
    --border-light:     #eef4fb;
    --surface:          #f7fafd;
    --shadow-sm:        0 1px 3px rgba(49,141,222,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:        0 4px 16px rgba(49,141,222,0.12), 0 2px 6px rgba(0,0,0,0.05);
    --shadow-lg:        0 12px 40px rgba(49,141,222,0.15), 0 4px 12px rgba(0,0,0,0.06);
    --radius-sm:        6px;
    --radius-md:        12px;
    --radius-lg:        20px;
    --radius-xl:        28px;
    --transition:       0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'DM Sans', sans-serif;
    background-color: var(--unitar-blue-mist);
    background-image:
        radial-gradient(ellipse 80% 50% at 20% -10%, rgba(49,141,222,0.12) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 110%, rgba(49,141,222,0.08) 0%, transparent 55%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

/* ── Container ── */
.chat-container {
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    max-width: 680px;
    width: 100%;
    height: 86vh;
    max-height: 820px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border);
    animation: containerReveal 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes containerReveal {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ── */
.chat-header {
    background: var(--unitar-blue);
    background-image: linear-gradient(135deg, var(--unitar-blue) 0%, var(--unitar-blue-dark) 100%);
    color: var(--white);
    padding: 28px 32px 24px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

/* Geometric accent — structural grid lines */
.chat-header::before {
    content: '';
    position: absolute;
    top: -40px;
    right: -40px;
    width: 200px;
    height: 200px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    pointer-events: none;
}

.chat-header::after {
    content: '';
    position: absolute;
    top: -20px;
    right: -20px;
    width: 140px;
    height: 140px;
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 50%;
    pointer-events: none;
}

.header-eyebrow {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    opacity: 0.7;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-eyebrow::before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 1px;
    background: rgba(255,255,255,0.5);
}

.chat-header h1 {
    font-family: 'DM Serif Display', serif;
    font-size: 22px;
    font-weight: 400;
    letter-spacing: -0.01em;
    line-height: 1.2;
    margin-bottom: 6px;
}

.chat-header p {
    font-size: 13px;
    font-weight: 300;
    opacity: 0.82;
    letter-spacing: 0.01em;
    line-height: 1.5;
}

/* ── Messages area ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 28px 28px 12px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--ink-tertiary);
}

/* ── Messages ── */
.message {
    display: flex;
    animation: messageIn 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
    margin-bottom: 8px;
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

.message.system {
    justify-content: center;
}

.message-content {
    max-width: 72%;
    padding: 13px 17px;
    border-radius: var(--radius-md);
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.65;
    font-size: 14.5px;
    font-weight: 400;
}

/* AI message — white card with blue left rule */
.message.ai .message-content {
    background: var(--white);
    color: var(--ink);
    border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    border-left: 3px solid var(--unitar-blue);
    position: relative;
}

/* User message — blue filled */
.message.user .message-content {
    background: var(--unitar-blue);
    color: var(--white);
    border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
    font-weight: 400;
    box-shadow: var(--shadow-md);
}

/* System message */
.message.system .message-content {
    background: var(--unitar-blue-pale);
    color: var(--unitar-blue-dark);
    border: 1px solid var(--border);
    font-size: 12.5px;
    max-width: 85%;
    border-radius: var(--radius-sm);
    text-align: center;
    padding: 8px 14px;
}

/* ── Typing indicator ── */
.typing-indicator {
    padding: 14px 18px;
    background: var(--white);
    border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    border-left: 3px solid var(--unitar-blue);
    width: fit-content;
    display: flex;
    align-items: center;
    gap: 5px;
}

.typing-indicator span {
    height: 7px;
    width: 7px;
    background: var(--unitar-blue);
    border-radius: 50%;
    display: inline-block;
    opacity: 0.6;
    animation: typingPulse 1.3s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.18s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.36s; }

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

/* ── Input area ── */
.chat-input-area {
    padding: 18px 24px 20px;
    background: var(--white);
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
}

#userInput {
    flex: 1;
    padding: 13px 18px;
    border: 1.5px solid var(--border);
    border-radius: 50px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14.5px;
    color: var(--ink);
    background: var(--surface);
    outline: none;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

#userInput::placeholder {
    color: var(--ink-tertiary);
    font-weight: 300;
}

#userInput:focus {
    border-color: var(--unitar-blue);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(49,141,222,0.1);
}

#userInput:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

#sendBtn {
    background: var(--unitar-blue);
    color: var(--white);
    border: none;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    font-weight: 500;
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
    position: relative;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#sendBtn:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 6px 20px rgba(49,141,222,0.35);
    background: var(--unitar-blue-dark);
}

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

#sendBtn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

#sendBtn.cooldown {
    background: var(--ink-tertiary);
    box-shadow: none;
    width: auto;
    border-radius: 50px;
    padding: 0 16px;
    font-size: 12px;
    height: 46px;
    letter-spacing: 0.02em;
}

.btn-text {
    font-family: 'DM Sans', sans-serif;
    font-size: 20px;
    line-height: 1;
}

/* Arrow icon for send button (CSS only) */
#sendBtn:not(.cooldown) .btn-text {
    font-size: 0;
}

#sendBtn:not(.cooldown) .btn-text::after {
    content: '↑';
    font-size: 18px;
    display: block;
}

/* ── Footer meta ── */
.api-status,
.rate-limit-info {
    font-size: 11px;
    color: var(--ink-tertiary);
    text-align: center;
    margin-top: 8px;
    letter-spacing: 0.02em;
}

.rate-limit-info {
    background: var(--surface);
    border-radius: 50px;
    padding: 4px 12px;
    border: 1px solid var(--border-light);
    display: inline-block;
    margin-left: auto;
    margin-right: auto;
    width: auto;
}

.api-status {
    margin-top: 6px;
}

/* center the footer items */
.chat-input-area > :not(.input-wrapper) {
    text-align: center;
}
