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

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a24;
    --accent: #00d4aa;
    --accent-dim: #00d4aa33;
    --text-primary: #e8e8e8;
    --text-secondary: #888;
    --border: #2a2a3a;
    --success: #00d4aa;
    --error: #ff4757;
    --warning: #ffa502;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Noto Sans SC', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    background-image:
        radial-gradient(ellipse at top left, #00d4aa08 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, #6366f108 0%, transparent 50%);
}

/* 全屏容器 */
.app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 顶部栏 */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.6rem;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.server-stats {
    display: flex;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
}

/* 认证区域 */
.auth-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    width: 100%;
    max-width: 360px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
}

.auth-card h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    text-align: center;
}

/* 主内容区 */
.main-content {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.main-content.active {
    display: flex;
}

/* 标签页导航 - 更紧凑 */
.tabs {
    display: flex;
    gap: 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 0.6rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* 标签内容 */
.tab-content {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.tab-content.active {
    display: flex;
}

/* 连接栏 - 内联紧凑 */
.connection-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.connection-bar input {
    flex: 1;
    min-width: 0;
    padding: 0.4rem 0.6rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

.connection-bar input:focus {
    outline: none;
    border-color: var(--accent);
}

.connection-bar input::placeholder {
    color: var(--text-secondary);
}

.connection-bar label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    background: var(--bg-card);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--error);
}

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

/* 消息头 */
.messages-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.75rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 0.5rem;
}

.messages-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.messages-header .meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    line-height: 1;
}

/* 消息列表 - 占满剩余空间，可滚动 */
.messages-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.5rem;
}

/* 对话回复栏 */
.reply-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.reply-bar input {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
}

.reply-bar input:focus {
    outline: none;
    border-color: var(--accent);
}

.reply-bar input::placeholder {
    color: var(--text-secondary);
}

.message-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.4rem;
    animation: slideIn 0.2s ease;
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

.message-item.selected {
    border-color: var(--accent);
    background: var(--accent-dim);
}

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

/* 自定义 Checkbox 样式 */
.custom-checkbox {
    position: relative;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin-top: 2px;
    cursor: pointer;
}

.custom-checkbox input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    margin: 0;
}

.custom-checkbox .checkmark {
    position: absolute;
    top: 0;
    left: 0;
    width: 18px;
    height: 18px;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 4px;
    transition: all 0.15s ease;
}

.custom-checkbox:hover .checkmark {
    border-color: var(--accent);
}

.custom-checkbox input:checked~.checkmark {
    background: var(--accent);
    border-color: var(--accent);
}

.custom-checkbox .checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 50%;
    top: 45%;
    width: 4px;
    height: 8px;
    border: solid var(--bg-primary);
    border-width: 0 2px 2px 0;
    transform: translate(-50%, -50%) rotate(45deg);
}

.custom-checkbox input:checked~.checkmark:after {
    display: block;
}

/* 全选标签样式 */
.select-all-label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    white-space: nowrap;
    color: inherit;
    padding: 0.25rem 0;
}

.select-all-label:hover {
    color: var(--text-primary);
}

.select-all-label .custom-checkbox {
    width: 12px;
    height: 12px;
    margin: 0;
    overflow: visible;
}

.select-all-label .checkmark {
    width: 12px;
    height: 12px;
    border-width: 1px;
}

/* 确认对话框 */
.confirm-dialog {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 360px;
    width: 100%;
    text-align: center;
}

.confirm-dialog h4 {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.confirm-dialog p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1.25rem;
}

.confirm-dialog .btn-group {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.confirm-dialog .btn-group button {
    min-width: 80px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.message-title {
    font-weight: 600;
    color: var(--accent);
    font-size: 0.9rem;
}

.message-client {
    font-size: 0.65rem;
    color: var(--text-hint);
    margin-right: 0.35rem;
}

.message-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.message-content {
    color: var(--text-primary);
    line-height: 1.15;
    font-size: 0.85rem;
    word-break: break-word;
    white-space: pre-wrap;
}

.message-content p {
    margin: 0;
    line-height: 1.15;
}

.message-content p+p {
    margin-top: 0.15em;
}

.message-content code {
    background: var(--bg-card);
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9em;
}

.message-content pre {
    margin: 0.2em 0;
    padding: 0.35rem 0.5rem;
    background: var(--bg-card);
    border-radius: 6px;
    overflow-x: auto;
    white-space: pre-wrap;
    line-height: 1.25;
}

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

.message-content ul,
.message-content ol {
    margin: 0;
    padding: 0 0 0 1.2rem;
    line-height: 1.15;
}

.message-content p+ul,
.message-content p+ol,
.message-content h1+ul,
.message-content h2+ul,
.message-content h3+ul,
.message-content strong+ul,
.message-content strong+ol {
    margin-top: 0.08em;
}

.message-content ul+p,
.message-content ol+p,
.message-content ul+h1,
.message-content ul+h2,
.message-content ul+h3 {
    margin-top: 0.08em;
}

.message-content ul+ul,
.message-content ol+ol,
.message-content ul+ol,
.message-content ol+ul {
    margin-top: 0.15em;
}

.message-content li {
    margin: 0;
    padding: 0;
    line-height: 1.15;
}

.message-content li p {
    margin: 0;
    line-height: 1.15;
}

.message-content li+li {
    margin-top: 0.02em;
}

.message-content a {
    color: var(--accent);
    text-decoration: none;
}

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

.message-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
    margin: 0.4em 0;
    vertical-align: middle;
}

.message-content blockquote {
    margin: 0.1em 0;
    padding-left: 0.75rem;
    border-left: 3px solid var(--border);
    color: var(--text-secondary);
    line-height: 1.15;
}

.message-content h1,
.message-content h2,
.message-content h3 {
    margin: 0.2em 0 0.05em;
    font-size: 1em;
    font-weight: 700;
    line-height: 1.15;
}

.message-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.25em 0;
}

/* Markdown 表格：边框与表头样式 */
.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.4em 0;
    font-size: 0.9em;
    background: var(--bg-card);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.message-content thead {
    background: var(--border);
}

.message-content th,
.message-content td {
    border: 1px solid var(--border);
    padding: 0.4em 0.6em;
    text-align: left;
    line-height: 1.3;
}

.message-content th {
    font-weight: 600;
    color: var(--text-primary);
}

.message-content tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.message-content tbody tr:hover {
    background: var(--accent-dim);
}

.message-topic {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 0.3rem;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 0.75rem;
    opacity: 0.3;
}

/* 发送消息面板 - 固定底部，紧凑布局 */
.send-panel {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    max-height: 38vh;
    overflow-y: auto;
}

.send-panel.collapsed {
    display: none;
}

.send-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.send-panel-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.send-panel-collapse {
    flex-shrink: 0;
}

/* 左下角悬浮图标 - 打开发送面板 */
.send-fab {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    z-index: 100;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

.send-fab:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

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

.send-fab.hidden {
    display: none;
}

.main-content:not(.active) .send-fab {
    display: none;
}

.main-content.active .send-fab.hidden {
    display: none;
}

.send-form {
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
}

.send-panel .form-group {
    margin-bottom: 0.35rem;
}

.send-panel .form-row {
    display: flex;
    gap: 0.5rem;
}

.send-panel .form-row .form-group {
    flex: 1;
}

.send-panel label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 0.15rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.send-panel input,
.send-panel textarea {
    width: 100%;
    padding: 0.35rem 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

.send-panel input:focus,
.send-panel textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.send-panel textarea {
    resize: vertical;
    min-height: 56px;
    max-height: 120px;
    font-family: 'Noto Sans SC', sans-serif;
}

.form-group {
    margin-bottom: 0.75rem;
}

.form-row {
    display: flex;
    gap: 0.75rem;
}

.form-row .form-group {
    flex: 1;
}

label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input,
textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
}

textarea {
    resize: vertical;
    min-height: 120px;
    font-family: 'Noto Sans SC', sans-serif;
}

/* 按钮 */
button,
.btn {
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8rem;
}

button:hover,
.btn:hover {
    filter: brightness(1.1);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

button.secondary:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

button.small {
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
}

/* 发送页：上传图片 */
.upload-area {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.send-panel .upload-area {
    margin-bottom: 0.35rem;
    gap: 0.35rem;
}

.send-panel .send-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.25rem;
    margin-bottom: 0.25rem;
    flex-wrap: wrap;
}

.send-panel .send-actions button {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
}

.send-panel .send-hint {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-left: 0.25rem;
}

.upload-area input[type="file"] {
    display: none;
}

.upload-files-list {
    font-size: 0.75rem;
    color: var(--text-secondary);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-files-list:empty::before {
    content: '未选择文件';
    color: var(--text-secondary);
    opacity: 0.8;
}

button.danger {
    background: var(--error);
}

button.small {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
}

button.full {
    width: 100%;
}

/* 响应框 */
.response-box {
    margin-top: 0.75rem;
    padding: 0.6rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    display: none;
}

.response-box.success {
    border-color: var(--success);
}

.response-box.error {
    border-color: var(--error);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    padding: 0.6rem 1rem;
    border-radius: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.85rem;
    animation: slideIn 0.2s ease;
    z-index: 1000;
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--error);
}

/* 模态框 */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 480px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideIn 0.2s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.25rem;
}

.modal-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

.help-section {
    margin-bottom: 1.25rem;
}

.help-section h4 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.help-section ul {
    list-style: none;
    font-size: 0.85rem;
}

.help-section li {
    padding: 0.3rem 0;
    color: var(--text-primary);
}

.code-block {
    display: block;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--accent);
    white-space: pre-wrap;
    word-break: break-all;
}

.help-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.help-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.help-link:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.help-footer {
    display: flex;
    justify-content: space-between;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* 响应式 */
@media (max-width: 640px) {
    .topbar {
        padding: 0.5rem;
    }

    .server-stats {
        display: none;
    }

    .connection-bar {
        flex-wrap: wrap;
    }

    .connection-bar input {
        flex: 1 1 100%;
    }

    .connection-bar input:first-of-type {
        flex: 2;
    }

    .connection-bar input:last-of-type {
        flex: 1;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }
}