/* ─── POE Chat — Dark Theme ─────────────────────────────────── */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-sidebar: #0f0f23;
    --bg-hover: #1a1a3e;
    --bg-active: #1e3a5f;
    --bg-input: #1e1e3a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #6c6c80;
    --accent: #4fc3f7;
    --accent-hover: #29b6f6;
    --accent-dim: rgba(79, 195, 247, 0.15);
    --user-bubble: #1e3a5f;
    --assistant-bubble: #1a1a3a;
    --border: #2a2a4a;
    --danger: #ef5350;
    --danger-hover: #e53935;
    --scrollbar-thumb: #3a3a5a;
    --scrollbar-track: #1a1a2e;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* ─── App Layout ───────────────────────────────────────────── */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ─── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

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

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header h2 span {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 14px;
}

.btn-new-chat {
    width: 100%;
    padding: 10px;
    margin-top: 12px;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-new-chat:hover {
    background: rgba(79, 195, 247, 0.25);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-list::-webkit-scrollbar {
    width: 6px;
}

.conversation-list::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

.conversation-list::-webkit-scrollbar-track {
    background: transparent;
}

.conv-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 4px;
    position: relative;
    border: 1px solid transparent;
}

.conv-item:hover {
    background: var(--bg-hover);
}

.conv-item.active {
    background: var(--bg-active);
    border-color: var(--accent);
}

.conv-item .conv-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.conv-item .conv-title {
    flex: 1;
    font-size: 13px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-item .conv-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 2px 4px;
    border-radius: 4px;
    transition: all 0.15s;
    flex-shrink: 0;
}

.conv-item:hover .conv-delete {
    opacity: 1;
}

.conv-item .conv-delete:hover {
    color: var(--danger);
    background: rgba(239, 83, 80, 0.15);
}

/* ─── Main Chat Area ───────────────────────────────────────── */
.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
}

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

.chat-header .chat-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.chat-header .btn-icon {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}

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

/* ─── Messages ─────────────────────────────────────────────── */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.message {
    display: flex;
    padding: 12px 24px;
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.message.user {
    background: transparent;
}

.message.assistant {
    background: rgba(255, 255, 255, 0.02);
}

.message .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 2px;
}

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

.message.assistant .avatar {
    background: rgba(76, 175, 80, 0.15);
    color: #66bb6a;
}

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

.message .bubble .content {
    line-height: 1.7;
    font-size: 15px;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

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

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

.message .bubble .content code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Consolas', 'Menlo', monospace;
    font-size: 13px;
    color: #ce93d8;
}

.message .bubble .content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid var(--border);
}

.message .bubble .content pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
}

/* ─── Typing Indicator ─────────────────────────────────────── */
.typing-indicator {
    display: flex;
    padding: 12px 24px;
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.typing-indicator .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(76, 175, 80, 0.15);
    color: #66bb6a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 2px;
}

.typing-indicator .dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 0;
}

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

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

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

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

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

.input-wrapper {
    display: flex;
    gap: 8px;
    max-width: 900px;
    margin: 0 auto;
    align-items: flex-end;
}

.input-wrapper textarea {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    min-height: 48px;
    max-height: 200px;
    line-height: 1.5;
    transition: border-color 0.2s;
}

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

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

.btn-send {
    padding: 12px 20px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    height: 48px;
    display: flex;
    align-items: center;
    gap: 4px;
}

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

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

/* ─── Empty State ──────────────────────────────────────────── */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

.empty-state .icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 20px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    max-width: 400px;
    line-height: 1.6;
}

/* ─── Token Info Bar ───────────────────────────────────────── */
.token-bar {
    display: flex;
    gap: 16px;
    padding: 6px 24px;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    overflow-x: auto;
}

.token-bar span {
    white-space: nowrap;
}

/* ─── Error Message ────────────────────────────────────────── */
.message.error .bubble .content {
    color: var(--danger);
}

.message.error .avatar {
    background: rgba(239, 83, 80, 0.15);
    color: var(--danger);
}

/* ─── Thinking/Reasoning Section ──────────────────────────── */
.thinking-section {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: rgba(255, 255, 255, 0.03);
}

.thinking-section.hidden {
    display: none;
}

.thinking-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}

.thinking-toggle:hover {
    background: rgba(255, 255, 255, 0.07);
}

.thinking-toggle .thinking-time {
    color: var(--text-muted);
    font-size: 11px;
}

.thinking-content {
    display: none;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'SF Mono', 'Consolas', 'Menlo', monospace;
}

.thinking-content::-webkit-scrollbar {
    width: 4px;
}

.thinking-content::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 2px;
}

/* Streaming pulse animation for content being generated */
.content.streaming::after {
    content: '▍';
    animation: cursor-blink 1s step-end infinite;
    color: var(--accent);
}

@keyframes cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ─── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        width: 200px;
        min-width: 200px;
    }

    .message {
        padding: 10px 16px;
    }

    .input-area {
        padding: 12px 16px;
    }
}
