/* 電台後台：沿用電台網站的色票與字型（app.css），只給後台自己的版面 */
:root {
  --bg: #F3F4F6; --surface: #FFFFFF; --ink: #121418; --muted: #5A616C; --line: #D6DAE0;
  --accent: #E0431A; --accent-ink: #FFFFFF; --chan: #1D6B57;
  --ok: #1D7A46; --warn: #B7791F; --bad: #C0392B;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0D0F12; --surface: #15181D; --ink: #ECEEF1; --muted: #98A0AB; --line: #2A2F37;
  --accent: #FF6A3D; --accent-ink: #0D0F12; --chan: #4FC3A1;
  --ok: #4CC38A; --warn: #E3B341; --bad: #FF6B5E;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D0F12; --surface: #15181D; --ink: #ECEEF1; --muted: #98A0AB; --line: #2A2F37;
    --accent: #FF6A3D; --accent-ink: #0D0F12; --chan: #4FC3A1;
    --ok: #4CC38A; --warn: #E3B341; --bad: #FF6B5E;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Noto Sans TC", system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 15px; line-height: 1.6; padding-bottom: env(safe-area-inset-bottom);
}
.mono { font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top, main { max-width: none; margin: 0; padding-inline: 16px; } /* 10-04 凱文：後台寬一點，左右不用留白 */
.top { display: flex; align-items: flex-end; justify-content: space-between; padding-block: 18px 10px; }
.eyebrow { margin: 0; font-size: 12px; color: var(--muted); letter-spacing: .08em; }
h1 { margin: 0; font-size: 26px; line-height: 1.2; }
.back { color: var(--muted); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
h2 { margin: 0; font-size: 18px; }
h3 { margin: 22px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.loading { color: var(--muted); }

/* 狀態燈 */
.lights { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.light { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; display: grid; gap: 2px; }
.light .k { font-size: 12px; color: var(--muted); }
.light .v { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.light .s { font-size: 12px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }

.counts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.count { border: 1px solid var(--line); border-radius: 999px; padding: 2px 12px; font-size: 13px; }
.count b { font-family: "IBM Plex Mono", ui-monospace, monospace; }

.book { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.book .name { font-weight: 600; overflow-wrap: anywhere; }
.book .num { font-size: 13px; color: var(--muted); text-align: right; }
.bar { grid-column: 1 / -1; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; display: flex; }
.bar span { display: block; height: 100%; }
.bar .pub { background: var(--chan); } .bar .gen { background: var(--warn); }

.sub { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.sub summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; color: var(--muted); }
.log { background: var(--bg); border-radius: 6px; padding: 10px; font-size: 12px; line-height: 1.5; max-height: 280px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.muted { color: var(--muted); font-size: 12px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { min-height: 36px; padding: 0 12px; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 700; }
.kpi .s { font-size: 12px; color: var(--muted); }

.chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; border-bottom: 1px solid var(--line); padding-top: 8px; }
.chart .col { flex: 1; min-width: 4px; background: var(--chan); border-radius: 2px 2px 0 0; position: relative; }
.chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* 前台編排 */
.lay-ch { border-top: 1px solid var(--line); padding: 10px 0; }
.lay-ch:first-child { border-top: 0; padding-top: 0; }
.lay-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; }
.lay-btns { display: flex; gap: 6px; flex: none; }
.lay-book { margin-left: 10px; border-top: 1px dashed var(--line); }
.lay-name { text-align: left; min-height: 40px; overflow-wrap: anywhere; }
.lay-eps { margin: 0 0 8px 18px; }
.lay-ep { border-top: 1px dotted var(--line); font-size: 14px; }
.off > .lay-row, .lay-ep.off { opacity: .55; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
th.n { text-align: right; }
td.n { text-align: right; font-family: "IBM Plex Mono", ui-monospace, monospace; white-space: nowrap; }

/* 09-30：許願審核、頻道設定 */
.wish-row { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.wish-row.pending { border-left: 3px solid var(--accent); padding-left: 10px; }
.wish-b { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.wish-ctl { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.wish-ctl select, .wish-ctl input { min-height: 40px; font: inherit; font-size: 14px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.wish-ctl input { flex: 1; min-width: 12em; }
.chan-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 10px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.chan-row strong { min-width: 7em; }
.chk { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
.chk input { width: 18px; height: 18px; }

/* ===== 10-01：分頁、會員、頁面編輯 ===== */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 16px; max-width: none; margin: 0 0 12px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 12px 14px; min-height: 44px; display: inline-flex; align-items: center; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 700; }
.tabs a[aria-current="true"] { color: var(--ink); border-bottom-color: var(--accent); }
/* 只顯示目前分頁的區塊（區塊本身的 hidden 照舊：還沒載到資料就不出現） */
#app[data-tab] > [data-tab] { display: none; }
#app[data-tab="overview"] > [data-tab="overview"]:not([hidden]),
#app[data-tab="data"] > [data-tab="data"]:not([hidden]),
#app[data-tab="members"] > [data-tab="members"]:not([hidden]),
#app[data-tab="visitors"] > [data-tab="visitors"]:not([hidden]),
#app[data-tab="usage"] > [data-tab="usage"]:not([hidden]),
#app[data-tab="content"] > [data-tab="content"]:not([hidden]),
#app[data-tab="tags"] > [data-tab="tags"]:not([hidden]),
#app[data-tab="wishes"] > [data-tab="wishes"]:not([hidden]) { display: block; }
#app[data-tab="overview"] > #lights:not([hidden]) { display: grid; }
.member-sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.filter { width: 100%; max-width: 360px; min-height: 40px; padding: 8px 10px; margin: 0 0 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.md-help code { background: var(--bg); padding: 1px 5px; }
.page-edit { border-top: 1px solid var(--line); padding: 10px 0; }
.page-edit summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; min-height: 40px; }
.badge { font-size: 12px; padding: 2px 8px; border: 1px solid var(--line); color: var(--muted); }
.badge.on { border-color: var(--chan); color: var(--chan); }
.page-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-top: 10px; }
.page-form { display: flex; flex-direction: column; gap: 10px; }
.page-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.page-form label.chk { flex-direction: row; color: var(--ink); }
.page-form input:not([type="checkbox"]), .page-form select, .page-form textarea { font: inherit; font-size: 14px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); padding: 8px 10px; min-height: 40px; width: 100%; box-sizing: border-box; }
.page-form textarea { font-family: ui-monospace, Menlo, Consolas, monospace; line-height: 1.6; }
.page-preview { border: 1px dashed var(--line); padding: 12px 14px; background: var(--bg); min-width: 0; }
.page-preview .info-block, .page-preview .plan { background: var(--surface); border: 1px solid var(--line); padding: 12px; margin-bottom: 10px; }
.page-preview .plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.page-preview .info-h, .page-preview .plan-name { font-size: 16px; margin: 0 0 8px; }
.page-preview .info-cta a { display: inline-block; background: var(--accent); color: var(--accent-ink); padding: 6px 12px; text-decoration: none; }
/* 10-01 階段 1：會員收聽歷程、留存表 */
.member-row { cursor: pointer; }
.member-row:hover, .member-row[aria-expanded="true"] { background: var(--bg); }
.member-detail > td { background: var(--bg); padding: 12px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.detail-grid h4 { margin: 0 0 6px; }
ul.plain { margin: 0; padding-left: 1.1em; line-height: 1.7; }
.retention td.ret { background: color-mix(in srgb, var(--chan) calc(var(--p) * 1%), transparent); }
/* 10-01 階段 2：節目標籤 */
.tag-filters { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-bottom: 8px; }
.tag-book { border-top: 1px solid var(--line); padding: 10px 0; }
.tag-book-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.tag-book-head h3 { margin: 0; font-size: 15px; }
.tag-ep { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.tag-ep-title { margin: 0 0 6px; font-size: 14px; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip { font: inherit; font-size: 13px; min-height: 36px; padding: 4px 10px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.tag-chip.on { border-color: var(--chan); color: var(--ink); background: color-mix(in srgb, var(--chan) 18%, transparent); }
.tag-chip.suggested { border-style: dashed; }
.tag-confirm, .tag-confirm-book { font: inherit; font-size: 13px; min-height: 36px; padding: 4px 12px; border: 1px solid var(--accent); color: var(--accent); background: transparent; cursor: pointer; }
/* 10-02：首頁標語 */
.hero-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; padding: 12px 0; border-top: 1px solid var(--line); }
.hero-pv-title { font-size: 22px; font-weight: 900; line-height: 1.3; margin: 0 0 8px; }
.hero-pv-sub { margin: 0; color: var(--muted); line-height: 1.6; }
.hero-del.armed { color: var(--accent); border-color: var(--accent); }
.exbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 10px 16px; }
#app[data-tab="data"] > #exBar, #app[data-tab="visitors"] > #exBar { display: flex; }
/* 10-02 凱文：節目資料庫（像 Notion 資料庫：一集一列，點開看細節） */
.epdb-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 8px; }
.epdb-tools .filter { margin: 0; max-width: 260px; }
.epdb-wrap { max-height: 70vh; overflow: auto; border: 1px solid var(--line); }
table.epdb { border-collapse: collapse; width: 100%; font-size: 13px; }
.epdb th { position: sticky; top: 0; z-index: 1; background: var(--surface); border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; padding: 8px; }
.epdb th.sortable { cursor: pointer; user-select: none; }
.epdb td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
.epdb .nowrap { white-space: nowrap; }
.epdb .ep-title { min-width: 16em; }
.epdb .ep-row { cursor: pointer; }
.epdb .ep-row:hover, .epdb .ep-row.open { background: var(--bg); }
.epdb .ep-row.is-hidden { opacity: .55; }
.tag-chip.mini { font-size: 11px; min-height: 0; padding: 1px 6px; cursor: default; display: inline-block; margin: 1px 0; }
.ep-detail > td { background: var(--bg); padding: 12px; }
.ep-detail-box { display: flex; flex-direction: column; gap: 10px; }
.ep-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.ep-tabs button { font: inherit; min-height: 36px; padding: 4px 12px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.ep-tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--chan); }
.ep-text { max-height: 50vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); padding: 10px 12px; margin: 0; white-space: pre-wrap; font: inherit; font-size: 14px; line-height: 1.75; }
.ep-text p { margin: 0 0 6px; }
#epConfirmAll.armed { color: var(--accent); border-color: var(--accent); }
/* 10-02：網站文字、電台名稱／介紹／顏色 */
.text-admin { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px 16px; margin-bottom: 10px; }
.text-row { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.text-row input, .chan-edit input:not([type="color"]) { font: inherit; font-size: 14px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); padding: 8px 10px; min-height: 40px; width: 100%; box-sizing: border-box; }
.chan-edit { flex-basis: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 12px; align-items: end; padding: 6px 0 4px; }
.chan-edit label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.chan-color input { width: 64px; height: 40px; padding: 0; border: 1px solid var(--line); background: none; }
/* 10-02：來源鏈 */
.lin-level { border-left: 3px solid var(--line); padding: 2px 0 6px 12px; margin: 0 0 10px; }
.lin-level h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); letter-spacing: .04em; }
.lin-node { background: var(--surface); border: 1px solid var(--line); padding: 8px 10px; margin: 0 0 6px; font-size: 13px; line-height: 1.6; }
.lin-loc { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.lin-small { font-size: 11px; }
.lin-edge { font-size: 12px; }

/* 10-04 用量分頁：額度色條（50% 黃、80% 紅） */
.ubar { height: 6px; background: var(--line); margin-top: 8px; overflow: hidden; }
.ubar span { display: block; height: 100%; background: var(--chan); }
.ubar.warm span { background: #D9A400; }
.ubar.hot span { background: var(--accent); }
.usage-setup ol { padding-left: 1.2em; line-height: 1.7; }
.usage-setup code { overflow-wrap: anywhere; }
.token-form { display: grid; gap: 6px; margin: 12px 0; }
.token-form label { font-weight: 700; }
.token-row { display: flex; gap: 8px; flex-wrap: wrap; }
.token-row input { flex: 1 1 220px; min-width: 0; min-height: 44px; font: inherit; padding: 8px 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.token-row button { min-height: 44px; }

/* 10-04 節目資料庫：Shownotes 編輯、素材欄、每日上架長條 */
.notes-edit { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.notes-col { min-width: 0; }
.notes-md { width: 100%; font: 14px/1.6 var(--mono, ui-monospace, monospace); padding: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.notes-preview { border: 1px solid var(--line); padding: 10px 12px; background: var(--surface); max-height: 420px; overflow: auto; }
.ep-src { min-width: 180px; font-size: 13px; }
.ep-daily .bar-cell { width: 40%; min-width: 80px; }
.ep-daily .ubar { display: block; margin-top: 4px; }
/* 10-04：欄位變多後表格很寬，展開的明細要固定在畫面可視範圍（不跟著表格撐寬，手機才不用往右滑才看到編輯框） */
.ep-detail-box { position: sticky; left: 0; max-width: calc(100vw - 64px); }
/* 10-04：自動標籤的理由（Codex 讀逐字稿；確認初稿時看） */
.tag-reasons { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.6; }
.tag-reasons .mono { margin-left: 6px; }
/* 10-04：電台、系列、集不要擠成好幾行（滿版後有空間） */
#epTable .ep-row > td:nth-child(-n+3) { white-space: nowrap; }
/* 10-04 凱文截圖：標籤欄被壓到一字寬，每個標籤的字直排，整列撐到幾百 px ⇒ 標籤不斷字、欄位給最小寬度 */
.tag-chip.mini { white-space: nowrap; }
#epTable td.ep-tags { min-width: 15em; }
