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

:root {
    --bg-primary: #212121;
    --bg-secondary: #2f2f2f;
    --bg-tertiary: #424242;
    --text-primary: #ececec;
    --text-secondary: #b4b4b4;
    --text-muted: #8e8e8e;
    --accent: #10a37f;
    --accent-hover: #1a7f64;
    --border: #444444;
    --user-msg-bg: #2f2f2f;
    --assistant-msg-bg: transparent;
    --error: #ef4444;
    --warning: #f59e0b;
    --success: #10a37f;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-tertiary: #ececec;
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --text-muted: #6e6e6e;
    --border: #e0e0e0;
    --user-msg-bg: #f7f7f8;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

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

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

.logo {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

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

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

.status-indicators {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.connected { background: var(--success); }
.status-dot.disconnected { background: var(--error); }
.status-dot.connecting {
    background: var(--warning);
    animation: pulse 1.5s ease-in-out infinite;
}

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

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

/* Main Chat Area */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
}

.messages {
    max-width: 768px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Message Styles */
.message {
    display: flex;
    gap: 16px;
    animation: fadeIn 0.3s ease-out;
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    color: white;
}

.message.user .message-avatar {
    background: #5436da;
}

.message.assistant .message-avatar {
    background: var(--accent);
}

.message.system .message-avatar {
    background: var(--bg-tertiary);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-role {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.message.user .message-role { color: #9d8df1; }
.message.assistant .message-role { color: var(--accent); }
.message.system .message-role { color: var(--text-muted); }

.message-text {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
}

.message.system .message-text {
    color: var(--text-muted);
    font-style: italic;
    font-size: 14px;
}

.message-text p { margin: 0 0 12px 0; }
.message-text p:last-child { margin-bottom: 0; }
.message-text ul, .message-text ol { margin: 8px 0; padding-left: 24px; }
.message-text li { margin: 4px 0; }

.message-text code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 14px;
}

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

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

.message-text a {
    color: var(--accent);
    text-decoration: none;
}

.message-text a:hover { text-decoration: underline; }

/* Tool Messages */
.message.tool-invocation .message-text {
    color: var(--warning);
    font-style: italic;
}

.message.tool-summary {
    background: rgba(16, 163, 127, 0.1);
    padding: 12px 16px;
    border-radius: 8px;
    border-left: 3px solid var(--accent);
}

/* Feedback Buttons */
.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions { opacity: 1; }

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
}

.action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.action-btn.selected { color: var(--accent); }
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Input Area */
.input-container {
    padding: 16px 24px 24px;
    background: var(--bg-primary);
    flex-shrink: 0;
}

.input-wrapper {
    max-width: 768px;
    margin: 0 auto;
}

.input-form {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 16px;
    transition: border-color 0.2s;
}

.input-form:focus-within {
    border-color: var(--accent);
}

.mode-toggle {
    display: flex;
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 2px;
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.mode-btn.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.mode-btn:hover:not(.active) {
    color: var(--text-secondary);
}

.text-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    resize: none;
    min-height: 24px;
    max-height: 200px;
}

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

.send-btn {
    background: var(--accent);
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled {
    background: var(--bg-tertiary);
    cursor: not-allowed;
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

/* Audio Mode Elements */
.audio-indicator {
    display: none;
    flex: 1;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 16px;
}

.audio-indicator.active { display: flex; }

.audio-waves {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 24px;
}

.wave-bar {
    width: 3px;
    background: var(--accent);
    border-radius: 2px;
    animation: wave 1.2s ease-in-out infinite;
}

.wave-bar:nth-child(1) { height: 8px; animation-delay: 0s; }
.wave-bar:nth-child(2) { height: 16px; animation-delay: 0.1s; }
.wave-bar:nth-child(3) { height: 24px; animation-delay: 0.2s; }
.wave-bar:nth-child(4) { height: 16px; animation-delay: 0.3s; }
.wave-bar:nth-child(5) { height: 8px; animation-delay: 0.4s; }

@keyframes wave {
    0%, 100% { transform: scaleY(0.5); }
    50% { transform: scaleY(1); }
}

.audio-status-text {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Settings Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

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

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.modal-close:hover { color: var(--text-primary); }

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.form-group {
    margin-bottom: 20px;
}

.form-group:last-child { margin-bottom: 0; }

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.form-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.form-select,
.form-textarea,
.form-input {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.form-select:focus,
.form-textarea:focus,
.form-input:focus {
    border-color: var(--accent);
}

.form-error {
    color: var(--error);
    font-size: 13px;
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 6px;
}

.form-textarea {
    min-height: 200px;
    resize: vertical;
    line-height: 1.5;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

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

.btn-primary {
    background: var(--accent);
    border: none;
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Login Gate */
.login-gate {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-gate-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
}

.login-gate-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

.login-gate-title {
    font-size: 24px;
    font-weight: 600;
}

.login-gate-text {
    font-size: 15px;
    color: var(--text-secondary);
    max-width: 360px;
}

.login-gate-btn {
    margin-top: 8px;
    padding: 10px 32px;
    font-size: 15px;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    background: var(--bg-secondary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.empty-state-icon svg {
    width: 32px;
    height: 32px;
    fill: var(--text-muted);
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-state-text {
    font-size: 14px;
    color: var(--text-muted);
    max-width: 400px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive */
@media (max-width: 640px) {
    .header { padding: 12px 16px; }
    .messages { padding: 0 16px; }
    .input-container { padding: 12px 16px 16px; }
    .status-indicators { display: none; }
}
