:root {
    --bg: #1e1e2e;
    --bg-surface: #282838;
    --bg-hover: #313144;
    --text: #cdd6f4;
    --text-dim: #6c7086;
    --accent: #89b4fa;
    --accent-dim: #45475a;
    --user-bg: #313244;
    --bot-bg: #1e1e2e;
    --border: #45475a;
    --danger: #f38ba8;
    --success: #a6e3a1;
    --warning: #f9e2af;
    --radius: 12px;
    --radius-sm: 8px;
}

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

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

#app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 800px;
    margin: 0 auto;
}

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

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

.logo {
    display: flex;
    align-items: center;
}

.title {
    font-weight: 600;
    font-size: 16px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.status-dot.connected { background: var(--success); }
.status-dot.disconnected { background: var(--danger); }
.status-dot.connecting { background: var(--warning); animation: pulse 1s infinite; }
.status-dot.busy { background: var(--accent); animation: pulse 0.5s infinite; }

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

.icon-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
}

.icon-btn:hover {
    background: var(--bg-hover);
}

/* Status banner */
.status-banner {
    padding: 8px 16px;
    text-align: center;
    font-size: 13px;
    color: var(--warning);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.status-banner.hidden {
    display: none;
}

/* Chat messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    -webkit-overflow-scrolling: touch;
}

.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-dim);
}

.welcome-message h2 {
    color: var(--text);
    margin-bottom: 8px;
    font-size: 20px;
}

.welcome-message .hint {
    margin-top: 12px;
    font-size: 13px;
}

.message {
    max-width: 90%;
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
}

.message.user {
    align-self: flex-end;
    background: var(--user-bg);
    border: 1px solid var(--border);
}

.message.assistant {
    align-self: flex-start;
    background: var(--bot-bg);
    border: 1px solid var(--border);
    max-width: 95%;
}

.message.assistant code {
    background: var(--bg-surface);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 13px;
}

.message.assistant pre {
    background: var(--bg-surface);
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
}

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

.message.error {
    align-self: center;
    color: var(--danger);
    background: transparent;
    border: 1px solid var(--danger);
    font-size: 13px;
}

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

.message .label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    color: var(--text-dim);
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing 1.2s infinite;
}

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

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

/* Input area */
.input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#chat-input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    outline: none;
    transition: border-color 0.2s;
}

#chat-input:focus {
    border-color: var(--accent);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: var(--bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    opacity: 0.8;
}

.input-options {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
}

.input-options select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    outline: none;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-content h3 {
    font-size: 18px;
}

.modal-content label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--text-dim);
}

.modal-content input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    outline: none;
}

.modal-content input:focus {
    border-color: var(--accent);
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg);
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

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

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
}

.btn-secondary:hover {
    background: var(--border);
}

/* Tool call cards */
.tool-calls-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 95%;
    align-self: flex-start;
    padding: 0 4px;
}

.tool-card {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-dim);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    cursor: default;
    flex-wrap: wrap;
    transition: background 0.15s;
}

.tool-card.expandable {
    cursor: pointer;
}

.tool-card.expandable:hover {
    background: var(--bg-hover);
}

.tool-card.expandable::after {
    content: '▸';
    font-size: 10px;
    margin-left: auto;
    transition: transform 0.15s;
}

.tool-card.expandable.expanded::after {
    transform: rotate(90deg);
}

.tool-icon {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.tool-icon svg {
    display: block;
}

.tool-title {
    font-weight: 500;
    color: var(--text);
}

.tool-detail {
    display: none;
    width: 100%;
    margin-top: 4px;
    padding: 6px 8px;
    background: var(--bg);
    border-radius: 4px;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 11px;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-dim);
}

.tool-card.expanded .tool-detail {
    display: block;
}

.tool-terminal { border-left: 3px solid var(--accent); }
.tool-file_edit { border-left: 3px solid var(--warning); }
.tool-file_create { border-left: 3px solid var(--success); }
.tool-search { border-left: 3px solid #cba6f7; }
.tool-read_file { border-left: 3px solid var(--text-dim); }
.tool-fetch { border-left: 3px solid #89dceb; }
.tool-files { border-left: 3px solid var(--warning); }

/* Safe area for notch phones */
@supports (padding: env(safe-area-inset-bottom)) {
    .input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
}
