:root {
    --bg-app: #0d1117;
    --bg-panel: #161b22;
    --bg-input: #21262d;
    --border: #30363d;
    --text-main: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #388bfd;
    --success: #3fb950;
    --warning: #d29922;
    --error: #f85149;
    --glass-bg: rgba(22, 27, 34, 0.85);
}

* {
    margin: 0; padding: 0; box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%; overflow: hidden;
    overscroll-behavior: none;
    position: fixed; width: 100%;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-app);
    color: var(--text-main);
    position: fixed; inset: 0;
    display: flex; flex-direction: column;
    overflow: hidden;
}

/* Header */
.header {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    z-index: 50;
}

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

.logo {
    font-size: 16px;
    font-weight: 700;
    background: linear-gradient(135deg, #58a6ff, #a371f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
}

.model-select {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 3px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    max-width: 90px;
}

.model-select:focus { border-color: var(--accent); }

.model-select option {
    background: var(--bg-panel);
    color: var(--text-main);
}

/* Quota Badge */
.quota-badge {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 3px 6px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 10px;
}

.quota-badge:hover { border-color: var(--text-muted); }

.quota-bar {
    width: 24px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.1);
    overflow: hidden;
}

.quota-fill {
    display: block;
    height: 100%;
    border-radius: 2px;
    background: var(--success);
    transition: width 0.5s, background 0.5s;
    width: 0%;
}

.quota-text {
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    font-size: 9px;
    min-width: 20px;
    text-align: right;
}

.status-dot {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--warning);
    transition: all 0.3s;
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

/* Header Buttons & Thread Dropdown */
.header-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.hdr-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.hdr-btn:hover { border-color: var(--text-muted); color: var(--text-main); }
.hdr-btn:active { transform: scale(0.95); }

.thread-dropdown-wrap {
    position: relative;
}

.thread-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 260px;
    max-width: 320px;
    max-height: 400px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    z-index: 100;
    overflow: hidden;
    animation: dropdown-in 0.15s ease;
}

.thread-dropdown.open { display: block; }

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

.thread-dropdown-header {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.thread-list {
    overflow-y: auto;
    max-height: 340px;
    padding: 4px;
}

.thread-list::-webkit-scrollbar { width: 0; }

.thread-item {
    display: block;
    width: 100%;
    padding: 8px 10px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-main);
    font-size: 13px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-item:hover { background: rgba(255,255,255,0.06); }
.thread-item.active { background: rgba(88,166,255,0.12); color: var(--accent); }

/* Chat Area */
.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-app);
}

.chat-content {
    min-height: 100%;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Welcome State */
.welcome-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 60vh;
    text-align: center;
    opacity: 0.7;
}

.welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #58a6ff, #a371f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-state h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 6px;
}

.welcome-state p {
    font-size: 14px;
    color: var(--text-muted);
}

/* Message Bubbles */
.message {
    max-width: 95%;
    line-height: 1.6;
    font-size: 14px;
}

.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    padding: 10px 14px;
    border-radius: 18px 18px 4px 18px;
    font-weight: 500;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 12px 16px;
    border-radius: 4px 18px 18px 18px;
}

.message.assistant pre {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    margin: 8px 0;
    overflow-x: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.assistant code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9em;
    background: var(--bg-input);
    padding: 1px 5px;
    border-radius: 3px;
}

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

/* Tool Calls */
.tool-call {
    background: rgba(163, 113, 247, 0.08);
    border: 1px solid rgba(163, 113, 247, 0.2);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: #a371f7;
    font-family: 'JetBrains Mono', monospace;
}

.tool-call .tool-label {
    font-weight: 600;
    margin-bottom: 4px;
}

.tool-call .tool-cmd {
    color: var(--text-muted);
    word-break: break-all;
}

/* Thinking indicator */
.thinking {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}

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

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

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

/* Input Section */
.input-section {
    background: var(--bg-panel);
    padding: 8px 16px 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 4px;
    align-items: center;
    background: var(--bg-input);
    padding: 4px 4px 4px 16px;
    border-radius: 24px;
    border: 1px solid var(--border);
    transition: all 0.2s;
    min-height: 48px;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 12px rgba(88, 166, 255, 0.15);
}

textarea {
    flex: 1;
    background: transparent !important;
    border: none !important;
    color: var(--text-main) !important;
    padding: 10px 0;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    min-height: 24px;
    max-height: 160px;
    line-height: 1.5;
    outline: none !important;
    -webkit-appearance: none;
    caret-color: var(--accent);
}

.send-btn {
    background: transparent;
    border: none;
    color: var(--accent);
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    align-self: flex-end;
    margin-bottom: 2px;
}

.send-btn:hover { background: rgba(88, 166, 255, 0.1); }
.send-btn:active { transform: scale(0.9); }

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

/* Voice Button */
.voice-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    align-self: flex-end;
    margin-bottom: 2px;
}

.voice-btn:hover { background: rgba(255,255,255,0.06); color: var(--accent); }
.voice-btn:active { transform: scale(0.9); }
.voice-btn svg { width: 20px; height: 20px; }

.voice-btn.recording {
    color: var(--error);
    animation: voice-pulse 1.5s infinite;
}

.voice-btn.recording .mic-icon { display: none; }
.voice-btn.recording .mic-off-icon { display: block !important; }

.voice-btn.hidden { display: none; }

@keyframes voice-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248,81,73,0.4); }
    50% { box-shadow: 0 0 0 8px rgba(248,81,73,0); }
}

/* Scrollbar */
.chat-container::-webkit-scrollbar { width: 0; }
textarea::-webkit-scrollbar { width: 0; }

/* ===== PWA 离线状态条 ===== */
.offline-bar {
    display: none;
    background: linear-gradient(135deg, #d29922, #e3a019);
    color: #0d1117;
    text-align: center;
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    z-index: 200;
    animation: slide-down 0.3s ease;
}

.offline-bar.show { display: block; }

/* ===== PWA 更新提示条 ===== */
.update-bar {
    display: none;
    background: linear-gradient(135deg, #388bfd, #58a6ff);
    color: #fff;
    text-align: center;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 500;
    flex-shrink: 0;
    z-index: 200;
    gap: 12px;
    align-items: center;
    justify-content: center;
    animation: slide-down 0.3s ease;
}

.update-bar.show { display: flex; }

.update-bar button {
    background: rgba(255,255,255,0.25);
    border: 1px solid rgba(255,255,255,0.4);
    color: #fff;
    padding: 3px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.update-bar button:hover { background: rgba(255,255,255,0.4); }

/* ===== PWA 安装提示 ===== */
.install-prompt {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 300;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    animation: slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.install-prompt.show { display: block; }

.install-prompt-content {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.install-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    flex-shrink: 0;
}

.install-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.install-text strong {
    font-size: 13px;
    color: var(--text-main);
}

.install-text span {
    font-size: 11px;
    color: var(--text-muted);
}

.install-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 16px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.install-btn:hover { background: var(--accent-hover); }
.install-btn:active { transform: scale(0.95); }

.install-dismiss {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color 0.2s;
}

.install-dismiss:hover { color: var(--text-main); }

/* ===== PWA 动画 ===== */
@keyframes slide-down {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slide-up {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

