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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: #ffffff;
    color: #1a1a1a;
    line-height: 1.6;
    height: 100dvh;
}

.app {
    max-width: 48rem;
    margin: 0 auto;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

.app.has-messages .welcome {
    display: none;
}

.app.has-messages .chat-area {
    flex: 1;
}

/* Empty state: input at exact vertical center, welcome text above it */
.app:not(.has-messages) .chat-area {
    display: none;
}

.app:not(.has-messages) .welcome {
    text-align: center;
    padding: 0 1.5rem;
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(50% + 2.5rem);
}

.app:not(.has-messages) .input-area {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    right: 0;
    max-width: 48rem;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}


.logo {
    font-size: 1.25rem;
    font-weight: 600;
    color: #111;
    letter-spacing: -0.03em;
}

.settings-btn {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 0.375rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: color 0.15s;
}

.settings-btn:hover {
    color: #555;
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.messages {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.welcome {
    text-align: center;
    color: #999;
}

.welcome h2 {
    font-size: 1.5rem;
    font-weight: 500;
    color: #333;
    margin-bottom: 0.5rem;
}

.welcome p {
    font-size: 0.9375rem;
    color: #888;
}

/* Messages */
.message {
    opacity: 0;
    animation: fadeIn 0.25s ease forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

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

.message.user .message-bubble {
    background: #f3f3f3;
    padding: 0.75rem 1rem;
    border-radius: 1.25rem;
    max-width: 80%;
    font-size: 0.9375rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

.message.assistant .response-content {
    font-size: 0.9375rem;
    line-height: 1.65;
}

/* Thinking Toggle */
.thinking-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: #999;
    cursor: pointer;
    padding: 0.25rem 0;
    margin-bottom: 0.75rem;
    border: none;
    background: none;
    user-select: none;
    transition: color 0.15s;
}

.thinking-toggle:hover {
    color: #666;
}

.thinking-toggle .chevron {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 0.625rem;
}

.thinking-toggle.open .chevron {
    transform: rotate(90deg);
}

.thinking-content {
    display: none;
    margin-bottom: 1rem;
    padding: 1rem;
    background: #fafafa;
    border-radius: 0.5rem;
    border: 1px solid #f0f0f0;
    font-size: 0.8375rem;
    color: #555;
    line-height: 1.6;
}

.thinking-content.open {
    display: block;
}

.thinking-content .model-response {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #f0f0f0;
}

.thinking-content .model-response:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.thinking-content .model-name {
    font-weight: 500;
    color: #888;
    font-size: 0.75rem;
    margin-bottom: 0.375rem;
    text-transform: lowercase;
}

/* Loading state */
.message.assistant.loading .response-content {
    display: none;
}

/* Progress feed */
.progress-feed {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    padding: 0.25rem 0;
}

.message.assistant:not(.loading) .progress-feed {
    display: none;
}

.progress-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: #888;
    opacity: 0;
    animation: slideIn 0.25s ease forwards;
}

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

.progress-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.progress-dot.spinning {
    background: #bbb;
    animation: progressPulse 1s infinite ease-in-out;
}

.progress-dot.done {
    background: #22c55e;
    animation: none;
}

@keyframes progressPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.progress-text {
    white-space: nowrap;
}

/* Input Area */
.input-area {
    padding: 0.75rem 1.5rem 1rem;
    flex-shrink: 0;
    transition: padding 0.3s ease;
}

.app:not(.has-messages) .input-area {
    padding: 0 1.5rem 0;
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 1.5rem;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    transition: border-color 0.15s, box-shadow 0.15s, padding 0.3s ease;
}

.app:not(.has-messages) .input-wrapper {
    padding: 0.75rem 0.625rem 0.75rem 1.25rem;
    border-color: #ccc;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.input-wrapper:focus-within {
    border-color: #999;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
}

#userInput {
    flex: 1;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.5;
    resize: none;
    max-height: 8rem;
    overflow-y: auto;
    padding: 0.25rem 0;
    background: transparent;
    transition: font-size 0.3s ease;
}

.app:not(.has-messages) #userInput {
    font-size: 1.0625rem;
}

#userInput::placeholder {
    color: #aaa;
}

.send-btn {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: none;
    background: #111;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, width 0.3s ease, height 0.3s ease;
}

.app:not(.has-messages) .send-btn {
    width: 2.25rem;
    height: 2.25rem;
}

.send-btn:hover {
    opacity: 0.8;
}

.send-btn:disabled {
    background: #ddd;
    cursor: not-allowed;
    opacity: 1;
}

/* Markdown content styles */
.response-content h1,
.response-content h2,
.response-content h3,
.response-content h4 {
    margin: 1.25rem 0 0.5rem 0;
    color: #111;
    font-weight: 600;
}

.response-content h1 { font-size: 1.25rem; }
.response-content h2 { font-size: 1.125rem; }
.response-content h3 { font-size: 1rem; }
.response-content h4 { font-size: 0.9375rem; }

.response-content p {
    margin-bottom: 0.75rem;
}

.response-content p:last-child {
    margin-bottom: 0;
}

.response-content ul,
.response-content ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}

.response-content li {
    margin-bottom: 0.25rem;
}

.response-content strong {
    font-weight: 600;
}

.response-content em {
    font-style: italic;
}

.response-content code {
    background: #f5f5f5;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-family: 'SF Mono', 'Menlo', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.85em;
}

.response-content pre {
    background: #f5f5f5;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 0.75rem 0;
}

.response-content pre code {
    background: none;
    padding: 0;
}

.response-content hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 1.5rem 0;
}

.response-content blockquote {
    border-left: 3px solid #ddd;
    padding-left: 1rem;
    color: #666;
    margin: 0.75rem 0;
}

/* Error message */
.error-message {
    background: #fef2f2;
    color: #dc2626;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
    max-width: 28rem;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #eee;
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #999;
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
}

.close-btn:hover {
    color: #555;
}

.modal-content {
    padding: 1.5rem;
}

.settings-section {
    margin-bottom: 1.25rem;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section > label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #555;
    margin-bottom: 0.5rem;
}

.settings-input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.15s;
    margin-bottom: 0.625rem;
}

.settings-input:last-of-type {
    margin-bottom: 0;
}

.settings-input:focus {
    outline: none;
    border-color: #999;
}

.settings-hint {
    font-size: 0.75rem;
    color: #aaa;
    margin-top: 0.25rem;
}

.settings-hint a {
    color: #666;
    text-decoration: underline;
}

/* Model picker */
.model-picker {
    position: relative;
    margin-bottom: 0.625rem;
}

.model-picker:last-of-type {
    margin-bottom: 0;
}

.model-picker input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

.model-picker input:focus {
    outline: none;
    border-color: #999;
}

.model-picker .dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 10rem;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 0.5rem 0.5rem;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.model-picker.open .dropdown {
    display: block;
}

.model-picker.open input {
    border-radius: 0.5rem 0.5rem 0 0;
}

.model-option {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.1s;
}

.model-option:hover {
    background: #f5f5f5;
}

.model-option .model-id {
    color: #333;
}

.model-option .model-price {
    color: #999;
    font-size: 0.75rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #eee;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.btn-primary,
.btn-secondary {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s;
}

.btn-primary {
    background: #111;
    color: #fff;
}

.btn-primary:hover {
    opacity: 0.85;
}

.btn-secondary {
    background: #f5f5f5;
    color: #555;
}

.btn-secondary:hover {
    background: #eee;
}

/* Responsive */
@media (max-width: 640px) {
    header {
        padding: 0.75rem 1rem;
    }

    .messages {
        padding: 1rem;
    }

    .input-area {
        padding: 0.75rem 1rem 1rem;
    }

    .app:not(.has-messages) .input-area {
        padding: 0 1rem;
    }

    .message.user .message-bubble {
        max-width: 90%;
    }

    .modal {
        width: 95%;
    }
}
