:root {
    --bg-color: #202024;
    --app-bg: #121212;
    --header-bg: #1e1e1e;
    --input-bg: #2c2c2c;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent-color: #00bcd4;
    --bubble-me: #005c4b;
    --bubble-other: #363636;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body, html {
    margin: 0; padding: 0; width: 100%; height: 100%;
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden; height: -webkit-fill-available;
}

/* 修正：手機版使用 fixed 鎖定，防止截圖中的跑版 */
.app-container {
    display: flex; flex-direction: column;
    background: var(--app-bg);
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%; height: 100dvh;
}

/* 電腦版樣式覆蓋 */
@media (min-width: 768px) {
    .app-container {
        position: relative; max-width: 900px; height: 85vh;
        margin: 4vh auto; border-radius: 16px;
        box-shadow: 0 20px 50px rgba(0,0,0,0.5);
        border: 1px solid rgba(255,255,255,0.1);
    }
}

/* Header */
.chat-header {
    flex: 0 0 56px; display: flex; align-items: center;
    justify-content: space-between; padding: 0 16px;
    background-color: var(--header-bg);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    z-index: 10;
}

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

.back-btn {
    background: transparent; border: none;
    color: var(--text-primary); cursor: pointer;
    padding: 8px; display: flex; align-items: center; justify-content: center;
    border-radius: 8px; transition: background-color 0.2s, transform 0.1s;
    flex-shrink: 0; width: 36px; height: 36px;
}

.back-btn:hover { background-color: rgba(255, 255, 255, 0.1); }
.back-btn:active { transform: scale(0.95); background-color: rgba(255, 255, 255, 0.15); }
.back-btn svg { width: 20px; height: 20px; stroke: var(--text-primary); }

.brand { font-size: 24px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.indicator { width: 3px; height: 18px; background: var(--accent-color); border-radius: 2px; }

.status-bar { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; }
.online-badge { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 20px; font-family: microsoft jhenghei;} /* 修正：字體改小 */
.online-badge .dot { width: 6px; height: 6px; background-color: #4caf50; border-radius: 50%; box-shadow: 0 0 4px #4caf50; }
.user-id { font-family: monospace; opacity: 0.7; margin-top: 2px; font-size: 18px;font-family: Arial, Helvetica, sans-serif; }

/* Chat Area */
.chat-area {
    flex: 1; min-height: 0; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px; display: flex; flex-direction: column; gap: 12px;
}

.msg.system {
    align-self: center; background: rgba(255,255,255,0.1);
    padding: 4px 12px; border-radius: 100px;
    font-size: 12px; color: var(--text-secondary);
    margin: 8px 0; text-align: center;
}

.msg.chat { display: flex; flex-direction: column; max-width: 80%; position: relative; }
.msg.chat { align-self: flex-start; }
.msg.chat .bubble {
    background-color: var(--bubble-other); padding: 10px 14px;
    border-radius: 12px; border-top-left-radius: 2px;
    color: #fff; word-break: break-word; line-height: 1.5;
}
.msg.chat .meta {
    font-size: 11px; color: var(--text-secondary);
    margin-top: 4px; margin-left: 2px; display: flex; gap: 8px;
}

.msg.chat.is-me { align-self: flex-end; align-items: flex-end; }
.msg.chat.is-me .bubble {
    background-color: var(--bubble-me);
    border-top-left-radius: 12px; border-top-right-radius: 2px;
}
.msg.chat.is-me .meta { flex-direction: row-reverse; margin-right: 2px; }

/* Footer */
.chat-footer {
    flex: 0 0 auto; background-color: var(--header-bg);
    padding: 10px 16px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255,255,255,0.1);
}

.composer { display: flex; gap: 10px; align-items: center; width: 100%; }

.input-field {
    flex: 1; background: var(--input-bg);
    border: 1px solid transparent; border-radius: 24px;
    padding: 12px 16px; color: #fff; font-size: 16px;
    outline: none; appearance: none; -webkit-appearance: none; margin: 0;
}

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

.send-btn {
    background: var(--accent-color); border: none;
    width: 44px; height: 44px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: #000; flex-shrink: 0;
    appearance: none; -webkit-appearance: none; margin: 0; padding: 0;
}
.send-btn:active { transform: scale(0.95); }

/* 手機版返回按鈕優化 */
@media (max-width: 600px) {
    .back-btn { width: 32px; height: 32px; padding: 6px; }
    .back-btn svg { width: 18px; height: 18px; }
    .header-left { gap: 8px; }
}