* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    height: 100vh;
    padding: 20px;
    overflow: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* ========== Header ========== */
header {
    background: white;
    padding: 20px 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
}

.nav-links {
    display: flex;
    gap: 10px;
    margin-right: 30px;
}

.nav-links a {
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    color: #666;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.3s;
    border: 2px solid transparent;
}

.nav-links a:hover {
    background: #e3f2fd;
    color: #1976d2;
}

.nav-links a.active {
    background: #1976d2;
    color: white;
    border-color: #1976d2;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-name {
    color: #666;
    font-size: 14px;
}

.btn-logout {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    color: #666;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
}

.btn-logout:hover {
    border-color: #1976d2;
    color: #1976d2;
}

/* ========== Main Content ========== */
.main-content {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ========== Session Sidebar ========== */
.session-sidebar {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar-header {
    padding: 16px 18px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.sidebar-header h2 {
    color: #1976d2;
    font-size: 16px;
}

.btn-new-session {
    padding: 5px 12px;
    border: 1px solid #1976d2;
    border-radius: 6px;
    background: white;
    color: #1976d2;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-new-session:hover {
    background: #1976d2;
    color: white;
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.session-list-empty {
    text-align: center;
    color: #bbb;
    font-size: 13px;
    padding: 30px 10px;
}

.session-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
    position: relative;
}

.session-item:hover {
    background: #f0f7ff;
}

.session-item.active {
    background: #e3f2fd;
}

.session-item-title {
    font-size: 13px;
    font-weight: 500;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 24px;
}

.session-item-meta {
    font-size: 11px;
    color: #999;
    margin-top: 3px;
}

.session-item-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: #ccc;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    display: none;
    align-items: center;
    justify-content: center;
}

.session-item:hover .session-item-delete {
    display: flex;
}

.session-item-delete:hover {
    background: #fee;
    color: #e53935;
}

/* ========== Chat Panel ========== */
.chat-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-header h2 {
    color: #1976d2;
    font-size: 18px;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

/* ========== Buttons ========== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-download {
    background: #1976d2;
    color: white;
    padding: 6px 14px;
    font-size: 13px;
}

.btn-download:hover {
    background: #1565c0;
}

.btn-clear {
    background: #f5f5f5;
    color: #666;
    padding: 6px 14px;
    font-size: 13px;
    border: 1px solid #ddd;
}

.btn-clear:hover {
    background: #eee;
    color: #333;
}

.btn-send {
    background: #1976d2;
    color: white;
    padding: 8px 20px;
    font-size: 14px;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: #1565c0;
}

.btn-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-attach {
    background: white;
    border: 1px solid #ddd;
    padding: 6px 10px;
    font-size: 18px;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 1;
    transition: all 0.2s;
}

.btn-attach:hover {
    border-color: #1976d2;
    background: #f0f7ff;
}

.btn-attach.has-files {
    border-color: #43a047;
    background: #e8f5e9;
}

/* ========== Chat Messages ========== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    font-size: 14px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 90%;
}

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.message-label {
    font-size: 12px;
    color: #999;
    margin-bottom: 4px;
}

.message.user .message-label {
    text-align: right;
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    overflow: hidden;
}

.message.user .message-content {
    background: #1976d2;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: #f5f5f5;
    color: #333;
    border-bottom-left-radius: 4px;
}

/* Markdown */
.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3 {
    margin: 12px 0 6px 0;
    color: #1976d2;
}

.message.assistant .message-content h1 { font-size: 18px; }
.message.assistant .message-content h2 { font-size: 16px; }
.message.assistant .message-content h3 { font-size: 14px; }

.message.assistant .message-content ul,
.message.assistant .message-content ol {
    margin: 6px 0;
    padding-left: 20px;
}

.message.assistant .message-content li {
    margin-bottom: 3px;
}

.message.assistant .message-content code {
    background: #e8e8e8;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 13px;
    font-family: 'Consolas', 'Monaco', monospace;
}

.message.assistant .message-content pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 12px 16px;
    border-radius: 8px;
    overflow-x: auto;
    max-width: 100%;
    margin: 8px 0;
    font-size: 13px;
    line-height: 1.4;
}

.message.assistant .message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.message.assistant .message-content table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
    table-layout: fixed;
    overflow-x: auto;
    display: block;
}

.message.assistant .message-content th,
.message.assistant .message-content td {
    border: 1px solid #ddd;
    padding: 6px 10px;
    font-size: 13px;
    text-align: left;
}

.message.assistant .message-content th {
    background: #e3f2fd;
    font-weight: 600;
}

/* Streaming */
.streaming-cursor::after {
    content: '|';
    animation: blink 0.8s infinite;
    color: #1976d2;
    font-weight: bold;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ========== Chat Input ========== */
.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

.chat-input-area textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.3s;
    max-height: 120px;
}

.chat-input-area textarea:focus {
    border-color: #1976d2;
}

/* ========== Attach Popover ========== */
.attach-popover {
    position: absolute;
    bottom: 80px;
    left: 24px;
    width: 340px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 100;
}

.popover-header {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    color: #333;
    font-size: 14px;
}

.popover-close {
    border: none;
    background: transparent;
    font-size: 18px;
    color: #999;
    cursor: pointer;
    padding: 0 4px;
}

.popover-close:hover {
    color: #333;
}

.popover-body {
    padding: 16px;
}

.popover-body .form-group {
    margin-bottom: 14px;
}

.popover-body .form-group:last-child {
    margin-bottom: 0;
}

.popover-body .form-group label {
    display: block;
    color: #333;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 5px;
}

.popover-body .form-group input[type="file"] {
    width: 100%;
    padding: 6px;
    border: 2px dashed #ccc;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

.popover-body .form-group input[type="file"]:hover {
    border-color: #1976d2;
}

.popover-body .form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    background: white;
}

.file-list {
    margin-top: 4px;
    font-size: 12px;
    color: #666;
}

.file-list .file-item {
    padding: 2px 6px;
    background: #f5f5f5;
    border-radius: 4px;
    margin-top: 2px;
    display: inline-block;
}

/* ========== Scrollbars ========== */
.chat-messages::-webkit-scrollbar,
.session-list::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.session-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.session-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.session-list::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}
