/* CILAR brand tokens (from cilar.webflow.io) */
:root {
    --cilar-yellow: #ffcc00;
    --cilar-yellow-soft: #fff6cc;
    --ink: #1a1b1f;
    --ink-soft: #43464d;
    --muted: #5f6570;
    --line: #e4ebf3;
    --surface: #ffffff;
    --surface-alt: #f5f7fa;
    --accent: #0050bd;
    --error-bg: #ffecec;
    --error: #b0003c;
    --radius-lg: 20px;
    --radius-md: 14px;
    --font-heading: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-body: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

[hidden] {
    display: none !important;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--surface-alt);
    color: var(--ink-soft);
    overflow: hidden;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.chat-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 960px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    background: var(--surface);
    box-shadow: 0 0 0 1px var(--line);
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    background: var(--ink);
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-logo {
    height: 30px;
    width: auto;
    display: block;
}

.brand-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.25);
}

.brand-product {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 18px;
    color: #fff;
    white-space: nowrap;
}

.new-chat-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 999px;
    background: transparent;
    color: #fff;
    font: 600 14px var(--font-body);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.new-chat-button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--cilar-yellow);
}

.new-chat-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    background: var(--surface);
}

.message {
    display: flex;
    gap: 16px;
    max-width: 820px;
    margin: 0 auto;
    padding: 24px;
    line-height: 1.7;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font: 600 13px var(--font-heading);
}

.message.user .message-avatar {
    background: var(--surface-alt);
    color: var(--ink);
    border: 1px solid var(--line);
}

.message.bot .message-avatar {
    background: var(--cilar-yellow);
    color: var(--ink);
}

.message-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.message.bot .message-body {
    flex: 1;
}

.message.user .message-body {
    align-items: flex-end;
    max-width: 80%;
}

.message-content {
    min-width: 0;
    font-size: 16px;
    color: var(--ink-soft);
    overflow-wrap: anywhere;
}

.message.user .message-content {
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg) 4px var(--radius-lg) var(--radius-lg);
    padding: 12px 18px;
    white-space: pre-wrap;
}

.message.bot .message-content {
    padding-top: 4px;
}

/* Bot message formatting */
.message-content > * + * {
    margin-top: 12px;
}

.message-content h2,
.message-content h3,
.message-content h4 {
    font-family: var(--font-heading);
    color: var(--ink);
    line-height: 1.35;
}

.message-content h2 { font-size: 20px; }
.message-content h3 { font-size: 18px; }
.message-content h4 { font-size: 16px; }

.message-content strong {
    font-weight: 700;
    color: var(--ink);
}

.message-content ul,
.message-content ol {
    padding-left: 24px;
}

.message-content li + li {
    margin-top: 4px;
}

.message-content a {
    color: var(--accent);
    text-underline-offset: 2px;
}

.message-content code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.9em;
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 1px 6px;
}

.message-actions {
    margin-top: 8px;
    display: flex;
    justify-content: flex-end;
}

.retry-button {
    border: none;
    background: none;
    color: var(--error);
    font: 600 13px var(--font-body);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    height: 28px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ink);
    opacity: 0.3;
    animation: typing 1.4s infinite;
}

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

@keyframes typing {
    0%, 60%, 100% { opacity: 0.25; transform: scale(0.8); }
    30% { opacity: 0.9; transform: scale(1); }
}

/* Welcome screen */
.welcome-screen {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
}

.welcome-mark {
    width: 72px;
    height: 72px;
    border-radius: 20px;
    background: var(--cilar-yellow);
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.welcome-title {
    font-family: var(--font-heading);
    font-size: 30px;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.25;
    margin-bottom: 12px;
    max-width: 640px;
}

.welcome-subtitle {
    font-size: 16px;
    color: var(--muted);
    line-height: 1.6;
    max-width: 560px;
    margin-bottom: 36px;
}

.example-prompts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 12px;
    width: 100%;
    max-width: 760px;
}

.example-prompt {
    padding: 16px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 4px solid var(--cilar-yellow);
    border-radius: var(--radius-md);
    color: var(--ink-soft);
    font: 15px/1.5 var(--font-body);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.example-prompt:hover:not(:disabled) {
    border-color: var(--cilar-yellow);
    box-shadow: 0 4px 14px rgba(26, 27, 31, 0.08);
    transform: translateY(-1px);
}

.example-prompt:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Status / errors */
.status-region:empty {
    display: none;
}

.status-message {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 24px 12px;
    padding: 12px 16px;
    border-radius: 10px;
    border-left: 4px solid var(--error);
    background: var(--error-bg);
    color: var(--error);
    font-size: 14px;
    line-height: 1.5;
}

.status-message.info {
    border-left-color: var(--cilar-yellow);
    background: var(--cilar-yellow-soft);
    color: var(--ink);
}

.status-message button {
    flex-shrink: 0;
    border: 1px solid currentColor;
    background: none;
    color: inherit;
    border-radius: 999px;
    padding: 4px 12px;
    font: 600 13px var(--font-body);
    cursor: pointer;
}

/* Input */
.chat-input-container {
    padding: 16px 24px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

.chat-input-wrapper {
    position: relative;
    max-width: 820px;
    margin: 0 auto;
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: 26px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.chat-input-wrapper:focus-within {
    background: var(--surface);
    border-color: var(--ink);
    box-shadow: 0 0 0 3px var(--cilar-yellow-soft);
}

.chat-input {
    display: block;
    width: 100%;
    min-height: 52px;
    max-height: 200px;
    padding: 14px 60px 14px 20px;
    border: none;
    background: transparent;
    outline: none;
    resize: none;
    font: 16px/1.5 var(--font-body);
    color: var(--ink);
}

.chat-input::placeholder {
    color: var(--muted);
}

.send-button {
    position: absolute;
    right: 7px;
    bottom: 7px;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--cilar-yellow);
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.06);
}

.send-button:disabled {
    background: var(--line);
    color: var(--muted);
    cursor: not-allowed;
}

.input-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    max-width: 820px;
    margin: 8px auto 0;
    padding: 0 8px;
    font-size: 12px;
    color: var(--muted);
}

.char-count.over-limit {
    color: var(--error);
    font-weight: 600;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: #bfc4ce; }

.fade-in {
    animation: fadeIn 0.25s ease;
}

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

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition: none !important;
    }
}

@media (max-width: 640px) {
    .chat-header { padding-left: 16px; padding-right: 16px; }
    .brand { gap: 10px; }
    .brand-logo { height: 22px; }
    .brand-product { font-size: 16px; }
    .new-chat-button span { display: none; }
    .new-chat-button { padding: 8px; }
    .message { padding: 18px 16px; gap: 12px; }
    .message-avatar { width: 32px; height: 32px; font-size: 12px; }
    .message.user .message-body { max-width: 88%; }
    .welcome-screen { padding: 28px 16px; }
    .welcome-title { font-size: 24px; }
    .welcome-subtitle { font-size: 15px; margin-bottom: 28px; }
    .chat-input-container { padding-left: 16px; padding-right: 16px; }
    .status-message { margin-left: 16px; margin-right: 16px; }
}
