/* ================================================================
   theater.css — 剧场 & 分支管理 UI 样式
   ================================================================ */

/* ── 通用隐藏 ────────────────────────────────────────────────── */
.theater-panel.hidden,
.theater-create-page.hidden,
.theater-modal-overlay.hidden,
.theater-branch-preview.hidden,
.theater-branch-more-detail.hidden,
.theater-name-row.hidden {
    display: none !important;
}

/* ── Tab 切换栏 ───────────────────────────────────────────────── */
.theater-panel-tabs {
    display: flex;
    border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.theater-tab {
    flex: 1;
    padding: 10px 0;
    background: none;
    border: none;
    font-size: 13px;
    color: #aaa;
    cursor: pointer;
    font-weight: 500;
    position: relative;
}

.theater-tab.active {
    color: #7c4dff;
}

.theater-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: #7c4dff;
    border-radius: 2px;
}

/* ── 剧场列表项 ───────────────────────────────────────────────── */
.theater-th-item {
    padding: 10px 16px;
    border-bottom: 1px solid #f5f5f5;
}

.theater-th-item.active {
    background: #faf7ff;
}

.theater-th-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.theater-th-left {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
}

.theater-th-name {
    font-size: 14px;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.theater-th-tag {
    font-size: 10px;
    background: #f0eaff;
    color: #7c4dff;
    padding: 1px 6px;
    border-radius: 8px;
    flex-shrink: 0;
}

.theater-th-tag.pub {
    background: #fff3e0;
    color: #e65100;
}

.theater-th-load-btn {
    flex-shrink: 0;
    padding: 5px 14px;
    background: #7c4dff;
    color: #fff;
    border: none;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 500;
}

.theater-th-load-btn:active {
    background: #6a3ce0;
}

.theater-th-edit-btn {
    flex-shrink: 0;
    padding: 5px 10px;
    background: none;
    color: #7c4dff;
    border: 1px solid #ddd;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
}

.theater-th-del-btn {
    flex-shrink: 0;
    padding: 5px 10px;
    background: none;
    color: #f44336;
    border: 1px solid #ffd0cc;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
}

.theater-th-del-confirm {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 4px 4px;
    flex-wrap: wrap;
}

.theater-th-preview {
    font-size: 12px;
    color: #aaa;
    margin-top: 4px;
    line-height: 1.5;
    word-break: break-all;
}

/* ── 分支管理面板 ─────────────────────────────────────────────── */
.theater-panel {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 3000;
    display: flex;
    align-items: flex-end;
}

.theater-panel-inner {
    background: #fff;
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.theater-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.theater-panel-title {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
}

.theater-panel-close {
    background: none;
    border: none;
    font-size: 22px;
    color: #999;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.theater-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}

.theater-panel-footer {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.theater-panel-footer button {
    flex: 1;
    padding: 10px 6px;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
}

.theater-btn-new {
    background: #7c4dff;
    color: #fff;
}

.theater-btn-fork {
    background: #f0eaff;
    color: #7c4dff;
}

.theater-btn-node {
    background: #f5f5f5;
    color: #555;
}

/* ── 分支列表项 ───────────────────────────────────────────────── */
.theater-branch-item {
    padding: 0 16px;
    border-bottom: 1px solid #f5f5f5;
}

.theater-branch-item.active {
    background: #faf7ff;
}

.theater-branch-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    cursor: pointer;
    gap: 8px;
}

.theater-branch-left {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
}

.theater-branch-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.theater-branch-name {
    font-size: 14px;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.theater-active-badge {
    font-size: 10px;
    background: #7c4dff;
    color: #fff;
    padding: 1px 6px;
    border-radius: 8px;
    flex-shrink: 0;
}

.theater-temp-badge {
    font-size: 10px;
    background: #ff9500;
    color: #fff;
    padding: 1px 6px;
    border-radius: 8px;
    flex-shrink: 0;
}

.theater-branch-theater {
    font-size: 11px;
    color: #9e69ff;
    max-width: 70px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.theater-branch-date {
    font-size: 11px;
    color: #aaa;
    flex-shrink: 0;
}

.theater-expand-btn {
    font-size: 11px;
    color: #bbb;
    cursor: pointer;
    padding: 2px 4px;
    flex-shrink: 0;
}

/* ── 预览消息区 ───────────────────────────────────────────────── */
.theater-branch-preview {
    padding: 6px 0 10px;
    border-top: 1px dashed #ebebeb;
}

.theater-preview-loading,
.theater-preview-empty {
    font-size: 12px;
    color: #bbb;
    padding: 6px 0;
    text-align: center;
}

.theater-preview-msg {
    display: flex;
    gap: 6px;
    align-items: flex-start;
    padding: 4px 0;
}

.theater-preview-role {
    font-size: 11px;
    color: #aaa;
    flex-shrink: 0;
    min-width: 20px;
}

.theater-preview-text {
    font-size: 12px;
    color: #555;
    line-height: 1.5;
    word-break: break-all;
}

.theater-preview-msg.assistant .theater-preview-role {
    color: #9e69ff;
}

/* ── 预览区操作栏（删除等） ───────────────────────────────────── */
.theater-preview-actions {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f5f5f5;
    display: flex;
    justify-content: flex-end;
}

.theater-preview-delete-btn {
    font-size: 12px;
    color: #e53935;
    background: none;
    border: 1px solid #ffcdd2;
    border-radius: 12px;
    padding: 4px 12px;
    cursor: pointer;
}

.theater-preview-delete-btn:active {
    background: #fff3f3;
}

/* ── 删除确认行 ───────────────────────────────────────────────── */
.theater-delete-confirm {
    margin-top: 8px;
    padding: 10px 12px;
    background: #fff8f8;
    border: 1px solid #ffcdd2;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.theater-delete-confirm-text {
    font-size: 12px;
    color: #c62828;
    font-weight: 500;
}

.theater-delete-confirm-btns {
    display: flex;
    gap: 8px;
}

.theater-delete-cancel-btn {
    flex: 1;
    padding: 7px 0;
    background: #f5f5f5;
    color: #555;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}

.theater-delete-ok-btn {
    flex: 1;
    padding: 7px 0;
    background: #e53935;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

.theater-delete-ok-btn:active {
    background: #c62828;
}

/* ── 更多/母节点 ──────────────────────────────────────────────── */
.theater-branch-more-row {
    padding: 4px 0 8px;
}

.theater-more-link {
    font-size: 11px;
    color: #aaa;
    cursor: pointer;
}

.theater-more-link:active {
    color: #7c4dff;
}

.theater-branch-more-detail {
    font-size: 11px;
    color: #888;
    padding: 4px 0 10px;
    line-height: 1.6;
}

.theater-parent-name {
    color: #7c4dff;
}

/* ── 状态文字 ─────────────────────────────────────────────────── */
.theater-loading,
.theater-empty,
.theater-error {
    text-align: center;
    padding: 32px 16px;
    font-size: 14px;
    color: #aaa;
}

.theater-error {
    color: #e53935;
}

/* ── 新建剧场页面 ─────────────────────────────────────────────── */
.theater-create-page {
    position: fixed;
    inset: 0;
    background: #fff;
    z-index: 3100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.theater-create-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.theater-create-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.theater-create-back {
    background: none;
    border: none;
    font-size: 20px;
    color: #555;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.theater-create-title {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
}

.theater-create-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.theater-create-footer {
    padding: 12px 16px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}

.theater-create-submit {
    width: 100%;
    padding: 13px 0;
    background: #7c4dff;
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 2px;
}

.theater-create-submit:active {
    background: #6a3ce0;
}

/* ── 表单字段 ─────────────────────────────────────────────────── */
.theater-field {
    margin-bottom: 20px;
}

.theater-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}

.theater-field-hint {
    font-size: 11px;
    color: #aaa;
    font-weight: 400;
}

.theater-field .required {
    color: #e53935;
}

.theater-field input[type="text"],
.theater-field textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    color: #1a1a1a;
    background: #fafafa;
    outline: none;
    resize: vertical;
    font-family: inherit;
    line-height: 1.5;
}

.theater-field input[type="text"]:focus,
.theater-field textarea:focus {
    border-color: #9e69ff;
    background: #fff;
}

/* ── 开场白输入行 ──────────────────────────────────────────────── */
.theater-opening-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-bottom: 8px;
}

.theater-opening-input {
    flex: 1;
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 13px;
    color: #1a1a1a;
    background: #fafafa;
    outline: none;
    resize: none;
    font-family: inherit;
}

.theater-opening-input:focus {
    border-color: #9e69ff;
    background: #fff;
}

.theater-opening-del {
    background: #f5f5f5;
    border: none;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    font-size: 18px;
    color: #aaa;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 2px;
}

.theater-add-opening {
    background: none;
    border: 1px dashed #c7b0ff;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    color: #9e69ff;
    cursor: pointer;
    width: 100%;
    text-align: center;
}

/* ── 公开 Toggle ──────────────────────────────────────────────── */
.theater-visibility-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theater-visibility-row label:first-child {
    margin-bottom: 0;
    flex-shrink: 0;
}

.theater-toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    margin-bottom: 0 !important;
}

.theater-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.theater-toggle-slider {
    position: absolute;
    inset: 0;
    background: #ccc;
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.2s;
}

.theater-toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.theater-toggle input:checked + .theater-toggle-slider {
    background: #7c4dff;
}

.theater-toggle input:checked + .theater-toggle-slider::before {
    transform: translateX(20px);
}

.theater-toggle input:disabled + .theater-toggle-slider {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ── 模态弹层（通用） ─────────────────────────────────────────── */
.theater-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 3200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

.theater-modal-box {
    background: #fff;
    border-radius: 16px;
    padding: 24px 20px 20px;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}

.theater-modal-title {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1a;
    margin-bottom: 8px;
    text-align: center;
}

.theater-modal-subtitle {
    font-size: 13px;
    color: #777;
    margin-bottom: 18px;
    text-align: center;
    line-height: 1.6;
}

.theater-modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.theater-modal-cancel,
.theater-modal-ok {
    flex: 1;
    padding: 11px 0;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    cursor: pointer;
    font-weight: 500;
}

.theater-modal-cancel {
    background: #f0f0f0;
    color: #555;
}

.theater-modal-cancel.danger {
    background: #fdecea;
    color: #e53935;
}

.theater-modal-ok {
    background: #7c4dff;
    color: #fff;
}

.theater-modal-ok:active {
    background: #6a3ce0;
}

.theater-modal-ok.secondary {
    background: #f0f0f0;
    color: #555;
}

.theater-modal-ok.secondary:active {
    background: #e0e0e0;
}

/* ── 另存一份 checkbox ────────────────────────────────────────── */
.theater-save-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #444;
    cursor: pointer;
    margin: 0 auto;
    width: fit-content;
}

.theater-save-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #7c4dff;
    cursor: pointer;
}

/* ── 命名输入框（modal 内） ───────────────────────────────────── */
.theater-name-row {
    margin-top: 10px;
}

.theater-name-row input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    color: #1a1a1a;
    background: #fafafa;
    outline: none;
    font-family: inherit;
}

.theater-name-row input:focus {
    border-color: #9e69ff;
    background: #fff;
}

/* ── 存档弹窗 ────────────────────────────────────────────────── */
.theater-save-overwrite-row {
    margin-bottom: 10px;
}
.theater-save-overwrite-row button {
    width: 100%;
}
.theater-save-new-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.theater-save-name-input {
    flex: 1;
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
}
.theater-save-name-input:focus {
    border-color: #9e69ff;
    background: #fff;
}

/* ── 初始状态栏输入区 ────────────────────────────────────────── */
.theater-isb-hint {
    font-size: 12px;
    color: #9e69ff;
    background: #f3eeff;
    border-radius: 8px;
    padding: 7px 10px;
    margin-bottom: 10px;
    line-height: 1.5;
}
.theater-isb-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.theater-isb-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.theater-isb-label {
    font-size: 13px;
    color: #666;
    width: 44px;
    flex-shrink: 0;
    text-align: right;
}
.theater-isb-input {
    flex: 1;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
    background: #fafafa;
}
.theater-isb-input:focus {
    border-color: #9e69ff;
    background: #fff;
}
.theater-isb-input[type=number] {
    max-width: 120px;
}

/* ── 从头/继续 两选项按钮 ─────────────────────────────────────── */
.theater-scratch-btns {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.theater-scratch-btn {
    width: 100%;
    padding: 13px 0;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    background: #7c4dff;
    color: #fff;
}

.theater-scratch-btn.secondary {
    background: #f0eaff;
    color: #7c4dff;
}

.theater-scratch-btn:active {
    opacity: 0.85;
}

/* ── 退出剧场按钮 ─────────────────────────────────────────────── */
.theater-exit-btn {
    padding: 5px 12px;
    background: rgba(124, 77, 255, 0.12);
    color: #7c4dff;
    border: 1px solid rgba(124, 77, 255, 0.3);
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.theater-exit-btn:active {
    background: rgba(124, 77, 255, 0.22);
}

/* 剧场激活状态指示条（fixed，紧贴 header 下方，和退出按钮同一排） */
.theater-active-indicator {
    position: fixed;
    top: calc(44px + env(safe-area-inset-top));
    left: 0;
    right: 0;
    z-index: 1050;
    display: none; /* JS 控制 flex/none */
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px 4px 16px;
    background: rgba(124,77,255,0.08);
    border-bottom: 1px solid rgba(124,77,255,0.15);
}

.theater-indicator-name {
    font-size: 11px;
    color: #7c4dff;
    font-weight: 500;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 有指示条时，内容区额外向下偏移（22px 约为指示条高度） */
#chat-page .content {
    /* 指示条高度由 JS 控制，padding-top 会在指示条显示时通过 CSS 变量或类补偿 */
}

/* ── 全新开始 LTM 策略弹窗 ─────────────────────────────────────── */
.theater-ltm-fresh-box {
    max-width: 320px;
}

.theater-ltm-fresh-subtitle {
    font-size: 13px;
    color: #888;
    text-align: center;
    margin-bottom: 20px;
}

.theater-ltm-fresh-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.theater-ltm-fresh-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: #f8f5ff;
    border: 1.5px solid #e8e0ff;
    border-radius: 14px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, border-color 0.15s;
    width: 100%;
    box-sizing: border-box;
}

.theater-ltm-fresh-btn:hover {
    background: #ede8ff;
    border-color: #c9b8ff;
}

.theater-ltm-fresh-btn:active {
    background: #e0d6ff;
}

.theater-ltm-fresh-text {
    display: flex;
    flex-direction: column;
}

.theater-ltm-fresh-label {
    display: block;
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    line-height: 1.3;
}

.theater-ltm-fresh-desc {
    display: block;
    font-size: 12px;
    color: #888;
    margin-top: 2px;
    line-height: 1.5;
}

.theater-ltm-persona-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 240px;
    overflow-y: auto;
}

.theater-ltm-loading {
    text-align: center;
    color: #aaa;
    font-size: 13px;
    padding: 16px 0;
}

.theater-ltm-skip-btn {
    margin-top: 4px;
    padding: 10px 16px;
    background: none;
    border: 1.5px solid #e0e0e0;
    border-radius: 10px;
    font-size: 14px;
    color: #888;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
    transition: background 0.15s;
}

.theater-ltm-skip-btn:hover {
    background: #f5f5f5;
}
