/* ═══════════════════════════════════════════
   帧知 - 视频学习Agent 样式
   ═══════════════════════════════════════════ */

:root {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --surface2: #252540;
    --border: #2a2a45;
    --text: #e0e0f0;
    --text-secondary: #9999bb;
    --primary: #6c5ce7;
    --primary-hover: #7d6ff0;
    --accent: #00d2a0;
    --danger: #e74c3c;
    --radius: 10px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

* { 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);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── 顶部栏 ── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 10;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon { font-size: 28px; }

.logo h1 {
    font-size: 22px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-sub {
    font-size: 13px;
    color: var(--text-secondary);
    margin-left: 4px;
}

.upload-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.cost-display {
    font-size: 13px;
    font-weight: 600;
    background: var(--surface2);
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 6px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
}
.cost-display:hover { background: var(--accent); color: #0f0f1a; }

/* ── 按钮 ── */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    font-family: inherit;
}

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

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 12px;
    padding: 8px 14px;
}
.btn-secondary:hover:not(:disabled) { border-color: var(--primary); }

.url-input {
    width: 280px;
    padding: 8px 14px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}
.url-input:focus { border-color: var(--primary); }
.url-input::placeholder { color: #555; }

.btn-send {
    background: var(--accent);
    color: #0f0f1a;
    padding: 10px 18px;
    font-weight: 600;
}
.btn-send:hover:not(:disabled) { filter: brightness(1.1); }

.mode-label {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 0;
}
.mode-label.vision-active {
    color: var(--accent);
    font-weight: 600;
}

/* ── 主体 ── */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── 视频面板 ── */
.video-panel {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    position: relative;
    min-width: 0;
}

.video-placeholder {
    text-align: center;
    color: var(--text-secondary);
}

.placeholder-icon { font-size: 64px; display: block; margin-bottom: 16px; }

.placeholder-content p {
    font-size: 16px;
    margin-bottom: 6px;
}

.placeholder-hint { font-size: 13px !important; color: #555; }

.video-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-container video {
    max-width: 100%;
    max-height: 100%;
    outline: none;
}

.subtitles-overlay {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.75);
    color: white;
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 15px;
    max-width: 80%;
    text-align: center;
    pointer-events: none;
}

/* ── 处理中遮罩 ── */
.processing-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.processing-detail {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ── 聊天面板 ── */
.chat-panel {
    width: 420px;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-left: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header h3 {
    font-size: 16px;
    flex-shrink: 0;
}

.video-name {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.btn-history {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
    flex-shrink: 0;
}
.btn-history:hover { border-color: var(--primary); color: var(--text); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.message {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
    animation: fadeIn 0.3s;
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    min-width: 0;
    max-width: 100%;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.system-msg {
    background: var(--surface2);
    color: var(--text-secondary);
}
.system-msg ul { margin: 8px 0 0 20px; }
.system-msg li { margin-bottom: 4px; }

.user-msg {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    max-width: 85%;
}

.assistant-msg {
    background: var(--surface2);
    border: 1px solid var(--border);
    max-width: 85%;
}

.timestamp-link {
    display: inline-block;
    background: var(--accent);
    color: #0f0f1a;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin: 0 2px;
    text-decoration: none;
    transition: filter 0.2s;
}
.timestamp-link:hover { filter: brightness(1.2); }

.frame-badge {
    display: inline-block;
    background: #e17055;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    margin-bottom: 8px;
}

.error-msg {
    background: var(--danger);
    color: white;
    font-size: 13px;
}

/* ── 输入区 ── */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-row {
    display: flex;
    gap: 8px;
}

#questionInput {
    flex: 1;
    padding: 10px 14px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
}

#questionInput:focus { border-color: var(--primary); }
#questionInput:disabled { opacity: 0.5; }

/* ── 历史记录列表 ── */
.history-list-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    padding: 4px 0 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.history-item {
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--surface2);
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 6px;
}
.history-item:hover { background: var(--border); }

.history-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 4px;
}

.history-item-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

/* ── 响应式 ── */
@media (max-width: 768px) {
    .main-container { flex-direction: column; }
    .chat-panel { width: 100%; height: 50%; }
}

/* ═══════════════════════════════════════════
   管理页（/admin）—— 试用者使用情况
   复用上面的 :root 变量，不引入新配色
   ═══════════════════════════════════════════ */

.topbar-link {
    margin-left: 10px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 13px;
    text-decoration: none;
    transition: color .18s ease, border-color .18s ease;
}
.topbar-link:hover { color: var(--accent); border-color: var(--accent); }

.admin-container {
    /* ★ `width: 100%` 不是可有可无的 —— 少了它，这一页的**宽度会跟着内容变**：
       主页的 `body` 是 `display:flex; flex-direction:column`，而本元素是它的
       flex item。在 flexbox 里，**cross 轴上的 auto margin（下面那句 `margin:0 auto`）
       会吃掉剩余空间**，于是它不再"拉伸填满"，而是**收缩到内容宽度**。
       后果实测（无头 Chrome 量的）：
           提问 71 字  → 容器 886px
           提问 142 字 → 容器 1363px（撞到视口）
       也就是"提问越长、整个界面越宽"。
       （另外 `max-width` 也不能救它 —— 那只是上限，下限仍由内容决定。
        我先把它从 1100 改到 2200 反而让能涨的范围更大，是治错了方向。）
    */
    width: 100%;
    max-width: 2200px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

.notice {
    padding: 10px 14px;
    margin-bottom: 16px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.7;
}
.notice-warn { border-color: var(--danger); color: var(--text); }

.admin-table {
    width: 100%;
    /* ★★ `table-layout: fixed` —— 让表格宽度**结构上**与内容无关。
       默认的 `auto` 布局里，表格的宽度是"内容想要的宽度"和"指定宽度"里取大者：
       哪怕写了 `width:100%`，只要某个单元格的最小内容宽度更大，**表格就会变宽**，
       把整个页面顶出去。fixed 布局则相反：列宽只由**第一行 + 显式宽度**决定，
       内容长了就在单元格里换行/溢出，**表格宽度一律等于指定的 100%**。
       （用户的要求原话："这个 ui 的宽度给我定死了，不论下面要显示多宽的内容
        这个 ui 的宽度禁止变化"。这就是那条要求对应的正确机制。） */
    table-layout: fixed;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    font-size: 13px;
}

/* 数字列给固定宽，剩下的由文字列（谁 / 最后活跃 / 状态）分。
   fixed 布局下没写宽度的列会平分剩余空间 —— 这些数字列很短，让它们均分太浪费。 */
.admin-table th.num, .admin-table td.num { width: 92px; }
.admin-table th,
.admin-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.admin-table th {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 12px;
    background: var(--surface2);
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table .cost-cell { color: var(--accent); }

/* ★ 单元格里的长串必须能断。
   表格有个容易忽略的特性：**它不会缩到比"内容的最小宽度"还窄** ——
   一个长标题、一段没有空格的长文本，就能把整张表顶宽，进而把整个页面顶宽
   （用户反馈"提问把那一段把界面撑宽了"就是这个）。 */
.admin-table th, .admin-table td { overflow-wrap: anywhere; }

.row-clickable { cursor: pointer; transition: background .15s ease; }
.row-clickable:hover { background: var(--surface2); }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    background: var(--surface2);
    color: var(--text-secondary);
    white-space: nowrap;
}
.badge-ok { color: var(--accent); }
.badge-warn { color: var(--danger); }
.badge-muted { color: var(--text-secondary); opacity: .75; }

.muted { color: var(--text-secondary); font-size: 12px; }

.detail-panel {
    margin-top: 22px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    /* 高度**有界**：点不同的人时内容多少差别很大（20 条提问 vs 0 条），
       不设框的话面板高度会大幅变、带动整页上下动。现在内容多了**面板内滚**，
       少了也不塌成一条。 */
    min-height: 180px;
    max-height: 70vh;
    overflow-y: auto;
    /* 面板自己就是滚动容器（上一行），所以这里要让滚动槽常驻 ——
       否则面板内一出现滚动条，它的**内容**会再窄 15px：同一个"宽度在变"的
       毛病换个地方犯。这里挂 scrollbar-gutter 是有效的（面板是自己的滚动容器，
       不涉及"body 的 overflow 传播到视口"那个坑）。 */
    scrollbar-gutter: stable;
}
.detail-head { display: flex; align-items: center; gap: 12px; }
.detail-head h3 { margin: 0; font-size: 15px; }
.detail-head .btn { margin-left: auto; }
.detail-panel h4 {
    margin: 20px 0 8px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}
.detail-panel .admin-table { box-shadow: none; font-size: 12.5px; }

.q-item {
    padding: 9px 12px;
    margin-bottom: 8px;
    background: var(--surface2);
    border-left: 3px solid var(--primary);
    border-radius: 6px;
}
.q-meta { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; }
/* 提问原文按**纯文本**呈现：靠 CSS 换行，而不是往 DOM 里拼 <br>
   （admin.js 里禁止 innerHTML，见那个文件开头的说明） */
.q-text {
    font-size: 12.5px;
    line-height: 1.65;
    white-space: pre-wrap;        /* 保留原文换行 */
    overflow-wrap: anywhere;      /* 没有空格的超长串（URL、长英文）也能断 */
    word-break: break-word;       /* 旧浏览器兜底 */
}

@media (max-width: 768px) {
    .admin-table th:nth-child(3), .admin-table td:nth-child(3) { display: none; }  /* 移动端先藏 token 列 */
}

/* 管理页要**整页滚动**，而主页的 body 在 style.css 顶部设了
   `height:100vh + overflow:hidden`（主页是固定视口的应用：顶栏 + 两栏，本身不滚动）。
   管理页是个长文档，复用那套样式会被裁在 100vh 里、滚不动 ——
   所以给它的 body 单独加这个类覆盖掉，**不动主页**。 */
body.admin-page {
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    /* ★ 用 `scroll` 而不是 `auto`：**滚动条始终占位**。
       用 auto 的话，点数据多的用户 → 页面变长 → 滚动条出现 → 可用宽度少约 15px
       → 面板和表格整体变窄；点数据少的又变宽 —— 表现就是"面板宽度在变"。
       （试过 `scrollbar-gutter: stable`，但 body 的 overflow 会**传播到视口**
        （html 是 visible 时），真正持有滚动条的是视口，那条属性挂在 body 上不可靠。）
       代价是右侧常驻一条滚动槽，换来确定性。 */
    overflow-y: scroll;
}

/* 切换用户时不要清空面板（那会让整页先缩再涨，看着忽大忽小）——
   保留上一个用户的内容、把它压暗，等新数据回来再替换。 */
.detail-panel.loading { opacity: .5; transition: opacity .15s ease; }

/* ── 密钥自检 ──
   和表格一样是"宽度由容器决定"，不要让它跟着名字/原因的长短变宽。 */
.key-check {
    margin-top: 22px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.key-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.key-head h3 { margin: 0; font-size: 15px; }
.key-list { margin: 12px 0; display: grid; gap: 6px; }
.key-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 13px;
    /* 原因里可能有很长的一串（撞车时会把两个名字都写出来），必须能断 */
    overflow-wrap: anywhere;
}
.key-mark { flex: none; }
.key-name { flex: none; font-weight: 500; }
.key-row-bad .key-name { color: var(--danger); }
.key-verify { display: flex; gap: 8px; flex-wrap: wrap; }
.key-verify input {
    /* flex:1 + min-width:0 —— 只写 flex:1 的话，input 的默认固有宽度会撑住它，
       窄屏上会把按钮挤出容器（和表格那个"内容撑宽"是同一类问题） */
    flex: 1;
    min-width: 240px;
    padding: 8px 14px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color .2s;
}
.key-verify input:focus { border-color: var(--primary); }
.key-verify input::placeholder { color: #555; }
.key-result { margin-top: 10px; overflow-wrap: anywhere; }
.key-result:empty { display: none; }

/* （详情面板的 min/max-height 与滚动约束合并到了上面那一个块里 ——
   同一个类散成两处，正是以后改漏一处的来源。） */
