/* For Impact Web Chat — mobile-first responsive design */

:root {
    --brand: #1a5276;
    --brand-light: #2980b9;
    --user-bg: #1a5276;
    --user-text: #ffffff;
    --assistant-bg: #f0f2f5;
    --assistant-text: #1a1a1a;
    --bg: #ffffff;
    --surface: #f8f9fa;
    --border: #e0e0e0;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --error: #dc2626;
    --radius: 12px;
    --max-width: 800px;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
}

body {
    display: flex;
    flex-direction: column;
    max-width: var(--max-width);
    margin: 0 auto;
}

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 10;
}

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

header h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--brand);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.connected {
    background: #22c55e;
}

.status-dot.disconnected {
    background: #ef4444;
}

#new-session {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--brand);
    background: transparent;
    border: 1px solid var(--brand);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

#new-session:hover {
    background: var(--brand);
    color: white;
}

/* Messages area */
main {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    line-height: 1.6;
}

.welcome-logo {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    margin-bottom: 16px;
}

.welcome-message strong {
    color: var(--brand);
    font-size: 17px;
}

/* Welcome how-to section */
.welcome-how {
    margin-top: 20px;
    text-align: left;
}

.welcome-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    margin-top: 20px;
    text-align: center;
}

.welcome-tips {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 400px;
    margin: 0 auto;
}

.welcome-tip {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 14px;
    color: var(--text);
    text-align: left;
    line-height: 1.4;
}

.tip-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

/* Sample prompts */
.sample-prompts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 440px;
    margin: 0 auto;
}

.sample-prompt {
    padding: 10px 14px;
    font-size: 13px;
    font-family: inherit;
    color: var(--brand);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    line-height: 1.4;
    transition: all 0.15s;
}

.sample-prompt:hover {
    background: var(--surface);
    border-color: var(--brand-light);
}

/* Header logo */
.header-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

/* Message rows (avatar + bubble) */
.message-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    max-width: 88%;
}

.message-row.assistant-row {
    align-self: flex-start;
}

.message-row .avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 2px;
}

/* Message bubbles */
.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius);
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-row .message {
    max-width: 100%;
    flex: 1;
    min-width: 0;
}

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

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

.message.error {
    align-self: flex-start;
    background: #fef2f2;
    color: var(--error);
    border: 1px solid #fecaca;
    border-bottom-left-radius: 4px;
}

.message.system {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
    padding: 4px 12px;
}

/* Markdown inside assistant messages */
.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
    margin-top: 12px;
    margin-bottom: 6px;
    font-size: 15px;
    font-weight: 700;
}

.message.assistant h1 { font-size: 17px; }
.message.assistant h2 { font-size: 16px; }

.message.assistant p {
    margin-bottom: 8px;
}

.message.assistant p:last-child {
    margin-bottom: 0;
}

.message.assistant ul,
.message.assistant ol {
    margin: 6px 0;
    padding-left: 20px;
}

.message.assistant li {
    margin-bottom: 4px;
}

.message.assistant strong {
    font-weight: 600;
}

.message.assistant code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.message.assistant pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}

.message.assistant pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.message.assistant blockquote {
    border-left: 3px solid var(--brand-light);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-muted);
}

.message.assistant hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

.message.assistant a {
    color: var(--brand-light);
    text-decoration: underline;
}

/* Message footer (cost/duration) */
.message-footer {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: right;
}

.message.assistant .message-footer {
    text-align: left;
}

/* Thinking indicator */
.thinking {
    align-self: flex-start;
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 0 4px;
}

.thinking .thinking-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    animation: pulse-glow 2s infinite ease-in-out;
}

.thinking .thinking-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.thinking .thinking-text {
    font-size: 14px;
    color: var(--brand);
    font-weight: 500;
    animation: fade-cycle 1s ease-in-out infinite alternate;
}

.thinking .thinking-sub {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.thinking .thinking-elapsed {
    font-variant-numeric: tabular-nums;
}

.thinking .thinking-dots span {
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: bounce 1.4s infinite ease-in-out;
}

.thinking .thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking .thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking .thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

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

@keyframes pulse-glow {
    0%, 100% { filter: brightness(1) drop-shadow(0 0 0 transparent); }
    50% { filter: brightness(1.1) drop-shadow(0 0 6px rgba(41, 128, 185, 0.3)); }
}

@keyframes fade-cycle {
    0% { opacity: 0.7; }
    100% { opacity: 1; }
}

/* File chips */
#file-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px;
    min-height: 0;
}

#file-chips:empty {
    display: none;
}

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    color: var(--text-muted);
}

.file-chip .remove {
    cursor: pointer;
    font-weight: bold;
    color: var(--text-muted);
    margin-left: 2px;
}

.file-chip .remove:hover {
    color: var(--error);
}

/* Input area */
footer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    bottom: 0;
}

#file-upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 50%;
    transition: all 0.15s;
    flex-shrink: 0;
}

#file-upload-label:hover {
    color: var(--brand);
    background: var(--surface);
}

#input {
    flex: 1;
    padding: 9px 14px;
    font-size: 15px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: 20px;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.15s;
}

#input:focus {
    border-color: var(--brand-light);
}

#send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: var(--brand);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}

#send:hover {
    background: var(--brand-light);
}

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

/* Drag-and-drop overlay */
.drag-over main {
    outline: 2px dashed var(--brand-light);
    outline-offset: -4px;
    background: rgba(41, 128, 185, 0.04);
}

/* Responsive */
@media (max-width: 600px) {
    body {
        max-width: 100%;
    }

    .message {
        max-width: 90%;
    }

    header h1 {
        font-size: 16px;
    }
}

@media (min-width: 800px) {
    body {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}
