* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    font-family: "Microsoft YaHei", "微软雅黑", sans-serif;
    font-size: 14px;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ======================== 侧边栏 ======================== */
#sidebar {
    width: 180px;
    min-width: 120px;
    max-width: 500px;
    background: #f5f5f5;
    border-right: 1px solid #ccc;
    display: flex;
    flex-direction: column;
    position: relative;
    flex-shrink: 0;
}

#sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #e0e0e0;
    height: 34px;
    padding: 0 8px;
    flex-shrink: 0;
}

#sidebar-title {
    font-weight: bold;
    font-size: 13px;
}

#btn-new-chat {
    background: none;
    border: none;
    font-size: 16px;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    padding: 2px 8px;
}

#btn-new-chat:hover {
    color: #1976d2;
}

#btn-config {
    background: none;
    border: none;
    font-size: 15px;
    color: #666;
    cursor: pointer;
    padding: 2px 6px;
    margin-left: 4px;
}

#btn-config:hover {
    color: #1976d2;
}

#sidebar-resize {
    position: absolute;
    right: -2px;
    top: 0;
    width: 4px;
    height: 100%;
    background: #ccc;
    cursor: ew-resize;
    z-index: 10;
}

#sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 2px;
}

.side-item {
    display: flex;
    align-items: flex-start;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 2px;
}

.side-item:hover {
    background: #e8e8e8;
}

.side-item.active {
    background: #d0e4f7;
}

.side-item .side-text {
    flex: 1;
    font-size: 12px;
    color: #333;
    word-break: break-all;
    line-height: 1.4;
}

.side-item .side-sub {
    font-size: 11px;
    color: #888;
}

.side-item .side-del {
    color: #cc0000;
    font-weight: bold;
    padding: 0 4px;
    flex-shrink: 0;
}

.side-item .side-del:hover {
    color: #ff0000;
}

.empty-hint {
    color: #999;
    text-align: center;
    padding: 20px;
    font-size: 12px;
}

/* ======================== 主区域 ======================== */
#main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #fff;
    min-width: 0;
}

#btn-toggle {
    position: absolute;
    top: 4px;
    left: 4px;
    z-index: 20;
    background: #e8e8e8;
    border: 1px solid #bbb;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    color: #666;
    padding: 2px 6px;
}

#btn-toggle:hover {
    background: #ddd;
}

/* 消息区 */
#msg-area {
    flex: 1;
    overflow-y: auto;
    padding: 30px 16px 8px;
}

#msg-list {
    display: flex;
    flex-direction: column;
}

.msg {
    padding: 3px 16px;
    border: 2px solid #ddd;
    border-radius: 6px;
    margin-bottom: 12px;
    background: #fff;
}

.msg .msg-role {
    font-weight: bold;
    font-size: 12px;
    margin-bottom: 3px;
}

.msg.user .msg-role {
    color: #1565c0;
    background: #f5f5f5;
}

.msg.ai .msg-role {
    color: #2e7d32;
    background: #f5f5f5;
}

.msg.system .msg-role {
    color: #888;
}

.msg .think-area {
    background: #f5f5f5;
    border-radius: 4px;
    margin: 4px 0;
    font-size: 12px;
    color: #888;
    font-style: italic;
}

.msg .think-header {
    background: #eee;
    padding: 2px 8px;
    cursor: pointer;
    user-select: none;
    font-style: normal;
}

.msg .think-header:hover {
    background: #e0e0e0;
}

.msg .think-body {
    padding: 4px 8px;
    /* word-break: break-word; */
    background: #f5f5f5;
}

.msg .msg-body {
    /* word-break: break-word; */
    line-height: 1.6;
}

.msg .ztl {
    background: #f5f5f5;
    color: #000000;
    padding: 0px 0px;
    cursor: pointer;
    user-select: none;
    font-style: normal;
    border-radius: 6px;
    margin-bottom: 6px;
}

.msg .tjl {
    background: #f5f5f5;
    color: #000000;
    padding: 8px 8px;
    cursor: pointer;
    user-select: none;
    font-style: normal;
    border-radius: 6px;
    margin-bottom: 6px;
}

.msg .al {
    background: #f5f5f5;
    color: #000000;
    padding: 1px 8px;
    cursor: pointer;
    user-select: none;
    font-style: normal;
    border-radius: 6px;
    margin-bottom: 6px;
}

.msg.system .msg-body {
    color: #888;
}

.msg.cursor::after {
    content: "▌";
    animation: blink 1s step-start infinite;
    color: #888;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* 翻页栏 */
#page-bar {
    display: flex;
    align-items: center;
    background: #f5f5f5;
    border-top: 1px solid #ddd;
    padding: 4px 8px;
    flex-shrink: 0;
}

#page-bar.hidden {
    display: none;
}

#page-bar button {
    background: none;
    border: none;
    color: #1976d2;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 8px;
}

#page-bar button:hover {
    text-decoration: underline;
}

#pb-info {
    flex: 1;
    text-align: center;
    color: #666;
    font-size: 12px;
}

/* 输入区 */
#input-frame {
    flex-shrink: 0;
    border-top: 1px solid #ddd;
    display: flex;
    flex-direction: column;
}

#input-resize {
    height: 4px;
    background: #ccc;
    cursor: ns-resize;
    flex-shrink: 0;
}

#status-bar {
    display: flex;
    align-items: center;
    background: #f0f0f0;
    height: 22px;
    font-size: 11px;
    padding: 0 8px;
    flex-shrink: 0;
}

#ctx-size {
    color: #888;
    margin-right: 12px;
}

#love-status {
    color: #e91e63;
    margin-right: 12px;
}

#speed-status {
    color: #888;
    margin-left: auto;
}

#input-text {
    border: 1px solid #ccc;
    border-radius: 4px;
    margin: 4px 8px;
    padding: 6px 8px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    min-height: 60px;
    max-height: 320px;
    flex-shrink: 0;
}

#input-text:focus {
    outline: none;
    border-color: #1976d2;
}

/* 工具栏 */
#toolbar {
    flex-shrink: 0;
    border-top: 1px solid #e0e0e0;
    padding: 6px 8px;
    background: #fafafa;
}

#toolbar-row1 {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

#toolbar label {
    font-size: 12px;
    color: #333;
}

#toolbar select {
    font-size: 12px;
    padding: 2px 4px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #fff;
}

#toolbar .chk {
    display: flex;
    align-items: center;
    gap: 2px;
}

#toolbar button {
    font-size: 12px;
    padding: 3px 10px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #f0f0f0;
    cursor: pointer;
}

#toolbar button:hover {
    background: #e0e0e0;
}

#btn-send {
    background: #1976d2 !important;
    color: #fff;
    border-color: #1976d2 !important;
    font-weight: bold;
}

#btn-send:hover {
    background: #1565c0 !important;
}

#btn-send:disabled {
    background: #bbb !important;
    border-color: #bbb !important;
    cursor: not-allowed;
}

/* ======================== 配置弹窗 ======================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #fff;
    border-radius: 8px;
    width: 900px;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-content.small {
    width: 560px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #f0f0f0;
    border-bottom: 1px solid #ddd;
    font-weight: bold;
}

.modal-header button {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: #666;
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid #ddd;
    background: #fafafa;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    border-bottom-color: #1976d2;
    color: #1976d2;
    font-weight: bold;
}

.tab-panel {
    display: none;
    padding: 12px;
    overflow-y: auto;
}

.tab-panel.active {
    display: block;
}

.panel-split {
    display: flex;
    gap: 12px;
}

.panel-list-wrap {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.panel-list-wrap ul {
    list-style: none;
    border: 1px solid #ddd;
    border-radius: 4px;
    height: 280px;
    overflow-y: auto;
}

.panel-list-wrap li {
    padding: 6px 10px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

.panel-list-wrap li:hover {
    background: #f0f0f0;
}

.panel-list-wrap li.active {
    background: #d0e4f7;
}

.panel-btns {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.panel-btns button {
    flex: 1;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #f5f5f5;
    cursor: pointer;
}

.panel-btns button:hover {
    background: #e8e8e8;
}

.panel-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.panel-form label {
    font-size: 12px;
    color: #555;
    margin-top: 4px;
}

.panel-form input,
.panel-form textarea,
.panel-form select {
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: inherit;
    font-size: 13px;
    width: 100%;
}

.panel-form textarea {
    resize: vertical;
}

.panel-form .inline {
    display: flex;
    gap: 6px;
}

.panel-form .inline input {
    flex: 1;
}

.panel-form .inline button {
    padding: 5px 10px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #f0f0f0;
    cursor: pointer;
    white-space: nowrap;
}

.panel-form .inline button:hover {
    background: #e0e0e0;
}

#char-gen-status {
    font-size: 12px;
    color: #888;
    min-height: 16px;
}

/* 字体设置 */
.font-group {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
}

.font-group h4 {
    margin-bottom: 8px;
    font-size: 13px;
}

.font-group .inline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.font-group .inline select {
    padding: 4px;
    border: 1px solid #ccc;
    border-radius: 3px;
    min-width: 160px;
}

.font-group .inline input[type="number"] {
    width: 60px;
    padding: 4px;
    border: 1px solid #ccc;
    border-radius: 3px;
}

.font-group .inline button {
    padding: 4px 10px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #f0f0f0;
    cursor: pointer;
}

.font-apply {
    text-align: center;
    margin-top: 8px;
}

.font-apply button {
    padding: 8px 24px;
    border: 1px solid #1976d2;
    border-radius: 4px;
    background: #1976d2;
    color: #fff;
    cursor: pointer;
}

.font-apply button:hover {
    background: #1565c0;
}

/* 右键菜单 */
.ctx-menu {
    position: fixed;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 200;
    min-width: 120px;
}

.ctx-menu.hidden {
    display: none;
}

.ctx-menu button {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
}

.ctx-menu button:hover {
    background: #f0f0f0;
}

/* 编辑弹窗 */
#edit-text {
    margin: 12px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
}

.edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 12px 12px;
}

.edit-actions button {
    padding: 6px 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
}

#btn-edit-save {
    background: #4caf50;
    color: #fff;
    border-color: #4caf50;
}

#btn-edit-cancel {
    background: #f0f0f0;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}