/* 后台管理系统外壳（规格 §5）：侧边栏、顶栏、内容区、页面构件（页头 / 区块 / 表格 / 页签 / 空状态 / 无权限页）、内嵌面板。
   沿用 app.css 的设计变量；深色主题，主色 #8B5CFF，红色只用于危险操作与告警。支持 1280px 宽。 */

:root { --sb-w: 216px; --sb-w-collapsed: 64px; }

.app[hidden], .wb[hidden], .page-host[hidden], .pg-foot[hidden], .wb-note[hidden], .modal-foot[hidden], .login-view[hidden] { display: none !important; }

/* ================= 骨架 ================= */
.app { position: fixed; inset: 0; display: grid; grid-template-columns: var(--sb-w) minmax(0, 1fr); transition: grid-template-columns .18s ease; }
.app.sb-collapsed { --sb-w: var(--sb-w-collapsed); }
.app-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.app-content { position: relative; flex: 1; min-height: 0; }
.page-host { height: 100%; overflow: auto; }
.page { padding: 20px 28px 40px; min-height: 100%; }
.page[data-page="analytics"], .page[data-page="analytics-session"] { padding: 16px 20px 28px; }

/* ================= 侧边栏 ================= */
.sidebar { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bar); border-right: 1px solid var(--line); overflow: hidden; }
.sb-brand { display: flex; align-items: center; height: var(--topbar-h); padding: 0 18px; border-bottom: 1px solid var(--line); text-decoration: none; flex: none; }
.sb-nav { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 10px 10px 8px; scrollbar-width: thin; }
.sb-group + .sb-group { margin-top: 6px; }
.sb-group-label { padding: 12px 12px 6px; font-size: 12px; font-weight: 700; letter-spacing: .6px; color: var(--dim); white-space: nowrap; }
.sb-group:first-child .sb-group-label { padding-top: 4px; }
.sb-group-rule { display: none; height: 1px; margin: 8px 10px; background: var(--line); }
.sb-item { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px; margin: 2px 0; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; position: relative; transition: background-color .15s, color .15s; }
.sb-item .ic { flex: none; }
.sb-item:hover { background: var(--panel-2); color: var(--fg); }
.sb-item.active { background: var(--accent-soft); color: #D5C6FF; }
.sb-item.active::before { content: ""; position: absolute; left: -10px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.sb-item:focus-visible, .sb-toggle:focus-visible, .sb-brand:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.sb-toggle { display: flex; align-items: center; gap: 12px; flex: none; height: 44px; padding: 0 22px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--dim); font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.sb-toggle:hover { color: var(--fg); background: var(--panel-2); }

.sidebar.collapsed .sb-brand { padding: 0; justify-content: center; }
.sidebar.collapsed .logo-text, .sidebar.collapsed .sb-label, .sidebar.collapsed .sb-group-label { display: none; }
.sidebar.collapsed .sb-group-rule { display: block; }
.sidebar.collapsed .sb-group:first-child .sb-group-rule { display: none; }
.sidebar.collapsed .sb-nav { padding: 10px 8px 8px; }
.sidebar.collapsed .sb-item { justify-content: center; padding: 0; }
.sidebar.collapsed .sb-item.active::before { left: -8px; }
.sidebar.collapsed .sb-toggle { justify-content: center; padding: 0; }

/* ================= 顶栏 ================= */
.app-top { display: flex; align-items: center; gap: 14px; height: var(--topbar-h); flex: none; padding: 0 20px; background: var(--bar); border-bottom: 1px solid var(--line); min-width: 0; }
.top-title { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.acct-btn { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px 0 5px; border-radius: var(--r-pill); border: 1px solid var(--line-2); background: transparent; color: var(--fg); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; transition: background-color .15s, border-color .15s; }
.acct-btn:hover { background: var(--panel-2); border-color: #3A4456; }
.acct-btn[aria-expanded="true"] { background: var(--panel-2); }
.acct-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-btn[hidden] { display: none; }

/* ================= 直播工作台（常驻容器） ================= */
.wb { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.wb-bar { display: flex; align-items: center; gap: 12px; flex: none; min-height: 52px; padding: 6px 16px; background: var(--bar); border-bottom: 1px solid var(--line); min-width: 0; }
.wb-note { display: flex; align-items: center; gap: 8px; flex: none; padding: 8px 18px; background: var(--warn-soft); color: #FFD88A; font-size: 13px; font-weight: 600; border-bottom: 1px solid rgba(255, 176, 32, .25); }
.wb > .ws-main { flex: 1 1 0; min-height: 0; grid-template-rows: minmax(0, 1fr); --pv-w: clamp(220px, calc((100vh - 286px) * 9 / 16), 32vw); }
.wb > .ws-onboarding { flex: 1 1 0; }
.wb > .ws-status { flex: none; height: var(--statusbar-h); }
.wb-bar .tiktok-pill:not([hidden]), .wb-bar .tiktok-detail:not([hidden]) { flex: none; }
.is-readonly { opacity: .5; filter: saturate(.5); }

/* ================= 提示 / 空状态 / 无权限页 ================= */
.state-page { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; padding: 72px 24px; }
.state-page.compact { padding: 36px 24px; }
.state-page .ph-title { font-size: 18px; font-weight: 800; }
.state-page .ph-text { max-width: 420px; }

/* ================= 页面构件 ================= */
.pg { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.pg-narrow { max-width: 780px; }
.pg-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.pg-head-text { min-width: 0; }
.pg-title { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: .2px; }
.pg-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.pg-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pg-body { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.pg-section { padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-card); }
.pg-section + .pg-section { margin-top: 0; }
.pg-section .section-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.pg-kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line); }
.pg-kv:last-of-type { border-bottom: 0; }
.pg-k { color: var(--muted); font-size: 13px; }
.pg-v { min-width: 0; word-break: break-word; }
.pg-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px 0 3px; border-radius: var(--r-pill); background: var(--panel-2); border: 1px solid var(--line-2); font-size: 13px; font-weight: 600; }
.pg-link-row { margin-top: 8px; }
.pg-form { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.pg-form .pg-actions { gap: 12px; }
.pg-foot { position: sticky; bottom: 12px; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--bar); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.pg-foot .foot-left { margin-right: auto; display: flex; align-items: center; gap: 10px; }
.pg-foot .foot-msg, .pg-form .foot-msg { flex: 1; min-width: 0; text-align: right; color: var(--danger); font-size: 13px; }
.pg-form .foot-msg { text-align: left; }

/* 页签 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; margin-bottom: -1px; padding: 10px 16px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; transition: color .15s, border-color .15s; }
.tab:hover { color: var(--fg); }
.tab.active { color: #fff; border-bottom-color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 8px; }

/* 表格 */
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--panel); }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--panel-2); white-space: nowrap; }
.tbl td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:first-child td { border-top: 0; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover { background: #1B2130; }
.tbl tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tbl .ta-right { text-align: right; }
.tbl .ta-center { text-align: center; }
.cell-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.cell-text small { font-size: 12px; }
.row-actions { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }

/* 只读围栏（fieldset[disabled] 让里面所有控件不可编辑） */
fieldset.ro-fence { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.ro-fence[disabled] { opacity: .82; }
fieldset.ro-fence :disabled { cursor: not-allowed; }

/* ================= 内嵌面板（弹窗内容改成页面） ================= */
.modal.modal-inline { width: auto; max-height: none; transform: none; box-shadow: none; transition: none; background: transparent; border: 0; border-radius: 0; }
.modal-inline > .modal-head { display: none; }
.modal-inline > .modal-body { overflow: visible; padding: 0; flex: none; }
.modal-inline > .modal-foot { position: sticky; bottom: 12px; z-index: 5; margin-top: 14px; padding: 12px 16px; background: var(--bar); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.modal-inline > .modal-body > .mb, .modal-inline > .modal-body > .mb-edit, .modal-inline > .modal-body > .fx-lib, .modal-inline > .modal-body > fieldset > .mb-edit {
  padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-card);
}

/* 个人设置里的权限标签等 */
.pg .tag { height: 24px; }

/* 数据看板页：去掉旧的 .ws-data 全屏内边距 */
.page .an-page { max-width: 1440px; }

/* ================= 窄屏 ================= */
@media (max-width: 1360px) {
  .page { padding: 16px 20px 32px; }
  .app-top { padding: 0 14px; }
  .acct-name { max-width: 96px; }
}
@media (max-width: 1320px) {
  .wb-bar .tool-btn .tool-label { display: none; }
  .wb-bar .tool-btn { width: 40px; padding: 0; justify-content: center; }
}
@media (max-width: 1100px) {
  .pg-kv { grid-template-columns: 1fr; gap: 2px; }
}

.cell-name { display: flex; align-items: center; gap: 8px; min-width: 0; }

/* ================= Group 4：观众 / 账号 / 角色 / 日志 ================= */
.pg-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pg-toolbar .select { width: auto; min-width: 140px; }
.pg-search { flex: 1; max-width: 380px; min-width: 220px; }
.pg-more { display: flex; justify-content: center; padding: 6px 0; }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: var(--mono); word-break: break-all; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; }
.row .input { flex: 1; min-width: 0; }

.hbars { display: flex; flex-direction: column; gap: 8px; }
.hbar-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) 150px; align-items: center; gap: 12px; font-size: 13px; }
.hbar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.hbar-track { height: 10px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: 6px; background: var(--accent); }
.hbar-val { text-align: right; color: var(--muted); }

.check-list { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow: auto; padding: 6px; border: 1px solid var(--line-2); border-radius: var(--r-ctl); background: var(--panel-2); }
.check-list[hidden] { display: none; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.check-row:hover { background: var(--panel-3); }
.check-row input { accent-color: var(--accent); }

.rl-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
.rl-list { display: flex; flex-direction: column; gap: 6px; }
.rl-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); font: inherit; text-align: left; cursor: pointer; }
.rl-item:hover { border-color: var(--accent-line); }
.rl-item.active { border-color: var(--accent); background: var(--accent-soft); }
.rl-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rl-edit { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.rl-edit .pg-section { display: flex; flex-direction: column; gap: 14px; }
.pm { display: flex; flex-direction: column; gap: 14px; }
.pm-title { margin: 0 0 4px; font-size: 13px; color: var(--muted); font-weight: 700; letter-spacing: .4px; }
.pm-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.pm-row:hover { background: var(--panel-2); }
.pm-row input { margin-top: 3px; accent-color: var(--accent); }
.pm-row.implied, .pm-row.ro { cursor: default; }
.pm-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.pm-id { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.pm-hint { color: #B9A0FF; font-size: 12px; }
.pm-text small { flex-basis: 100%; }

.audit-tbl td { vertical-align: top; }
.audit-detail-row td { background: var(--panel-2); padding: 12px 18px; }
.audit-detail { display: flex; flex-direction: column; }
.audit-kv { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line-2); }
.audit-detail .pg-kv { padding: 4px 0; border-bottom: 0; grid-template-columns: 120px minmax(0, 1fr); }

@media (max-width: 1360px) { .rl-layout { grid-template-columns: 240px minmax(0, 1fr); } .hbar-row { grid-template-columns: 90px minmax(0, 1fr) 130px; } }
