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

:root {
    --bg-primary: #343541;
    --bg-secondary: #202123;
    --bg-message-user: #343541;
    --bg-message-ai: #444654;
    --text-primary: #ececf1;
    --text-secondary: #8e8ea0;
    --border-color: #4d4d4f;
    --accent-color: #10a37f;
    --hover-color: #2a2b32;
    --sidebar-width: 260px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* ============ 側邊欄 ============ */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header .new-chat-btn {
    width: 100%;
    justify-content: center;
}

/* 歷史紀錄列表 */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-bottom: 2px;
}

.chat-history-item:hover {
    background-color: var(--hover-color);
}

.chat-history-item.active {
    background-color: var(--hover-color);
}

.chat-history-item .chat-icon {
    flex-shrink: 0;
    color: var(--text-secondary);
}

.chat-history-item .chat-title {
    flex: 1;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-item .delete-btn {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: opacity 0.2s, color 0.2s;
}

.chat-history-item:hover .delete-btn {
    opacity: 1;
}

.chat-history-item .delete-btn:hover {
    color: #ef4444;
}

/* 側邊欄遮罩（手機版） */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
}

/* ============ 主要內容區 ============ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-width: 0;
}

.header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.header h1 {
    font-size: 16px;
    font-weight: 500;
}

/* 服務狀態指示燈 */
.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-left: 8px;
    background-color: #6b7280;
    transition: background-color 0.3s;
}

.status-indicator.online {
    background-color: #10b981;
    box-shadow: 0 0 6px #10b981;
}

.status-indicator.offline {
    background-color: #ef4444;
    box-shadow: 0 0 6px #ef4444;
}

/* 漢堡選單按鈕（預設隱藏） */
.menu-btn {
    display: none;
    position: absolute;
    left: 12px;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
}

.menu-btn:hover {
    background-color: var(--hover-color);
}

/* 手機版新對話按鈕（預設隱藏） */
.mobile-new-chat {
    display: none;
    position: absolute;
    right: 12px;
}

/* ============ 新對話按鈕 ============ */
.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.new-chat-btn:hover {
    background-color: var(--hover-color);
}

.model-badge {
    font-size: 12px;
    padding: 4px 8px;
    background-color: var(--bg-secondary);
    border-radius: 4px;
    color: var(--text-secondary);
}

/* 聊天容器 */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
}

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

.welcome-message p {
    font-size: 16px;
}

/* 訊息樣式 */
.message {
    padding: 20px;
    display: flex;
    gap: 16px;
    max-width: 800px;
    margin: 0 auto;
}

.message.user {
    background-color: var(--bg-message-user);
    flex-direction: row-reverse;
}

.message.assistant {
    background-color: var(--bg-message-ai);
    flex-direction: row;
    border-radius: 8px;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 4px;
}

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

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

.message-content {
    flex: 1;
    line-height: 1.6;
    font-size: 15px;
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 36px;
}

.message.user .message-content {
    text-align: left;
    align-items: flex-end;
}

.message.assistant .message-content {
    text-align: left;
    align-items: flex-start;
}

.message-content p {
    margin-bottom: 12px;
}

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

/* Markdown 表格樣式 */
.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    text-align: left;
}

.message-content th {
    background-color: var(--bg-secondary);
    font-weight: 600;
}

.message-content tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.1);
}

/* Markdown 程式碼樣式 */
.message-content code {
    background-color: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 14px;
}

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

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

/* Markdown 清單樣式 */
.message-content ul,
.message-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-content li {
    margin-bottom: 6px;
}

/* Markdown 標題樣式 */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin: 16px 0 8px 0;
    font-weight: 600;
}

.message-content h1 { font-size: 1.5em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.1em; }

/* Markdown 引用樣式 */
.message-content blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-secondary);
}

/* Markdown 連結樣式 */
.message-content a {
    color: var(--accent-color);
    text-decoration: none;
}

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

/* 載入動畫 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.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% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* 輸入區域 */
.input-area {
    padding: 20px;
    background-color: var(--bg-primary);
}

.input-wrapper {
    max-width: 760px;
    margin: 0 auto 20px auto;
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 16px;
}

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

.input-wrapper textarea::placeholder {
    color: var(--text-secondary);
}

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

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

.send-btn:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
    opacity: 0.5;
}

.disclaimer {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 12px;
}

/* 滾動條樣式 */
::-webkit-scrollbar {
    width: 8px;
}

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

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

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

/* ============ 響應式設計 ============ */
@media (max-width: 768px) {
    /* 側邊欄預設隱藏 */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    /* 顯示漢堡選單 */
    .menu-btn {
        display: flex;
    }

    /* 顯示手機版新對話按鈕 */
    .mobile-new-chat {
        display: flex;
        padding: 8px;
        border: none;
    }

    .message {
        padding: 16px;
    }

    .input-wrapper {
        margin: 0 12px 20px 12px;
    }
}
