:root {
  --ink: #17171a; --ink-2: #55565c; --ink-3: #8a8b92; --line: #e6e6ea; --line-2: #f0f0f3;
  --bg: #f6f6f8; --card: #fff; --accent: #c8102e; --accent-2: #a50d26;
  --blue: #2563eb; --green: #15803d; --amber: #b45309; --red: #c81e1e; --orange: #c2410c; --gray: #6b7280;
  --tg: #3390ec; --tg-bg: #e9eef3;
  --r: 10px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.5;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.boot { padding: 80px; text-align: center; color: var(--ink-3); }

/* 登入 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { margin: 0 0 24px; color: var(--ink-3); }
.login .field { margin-bottom: 14px; }
.login button { width: 100%; margin-top: 8px; }

/* 版面 */
header.top { position: sticky; top: 0; z-index: 20; background: var(--ink); color: #fff; display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 52px; }
header.top .brand { font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
header.top .brand span { color: #ff5470; }
header.top nav { display: flex; gap: 2px; height: 100%; }
header.top nav a { color: #c9c9ce; text-decoration: none; padding: 0 14px; display: flex; align-items: center; border-bottom: 2px solid transparent; }
header.top nav a:hover { color: #fff; }
header.top nav a.on { color: #fff; border-bottom-color: #ff5470; }
header.top .right { margin-left: auto; display: flex; align-items: center; gap: 14px; white-space: nowrap; }
header.top .who { color: #c9c9ce; font-size: 13px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 0; cursor: default; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.on { background: #dcfce7; color: var(--green); }
.pill.off { background: #3a3a40; color: #d4d4d8; }
.pill.click { cursor: pointer; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 80px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; margin: 0; margin-right: auto; }

/* 按鈕與表單 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; white-space: nowrap; font-weight: 500; }
.btn:hover { background: var(--line-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: #fef2f2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.input, select.input, textarea.input { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none; }
textarea.input { height: auto; padding: 10px; resize: vertical; line-height: 1.6; }
.input:focus { border-color: var(--ink-3); box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.err-text { color: var(--red); }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 0 12px; height: 34px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: #fff; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 4px 12px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip .n { opacity: .6; margin-left: 4px; }

/* 狀態 */
.st { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-draft { background: #f1f1f4; color: var(--gray); }
.st-scheduled { background: #e0ebff; color: var(--blue); }
.st-sending { background: #fef3c7; color: var(--amber); }
.st-sent { background: #dcfce7; color: var(--green); }
.st-failed { background: #fee2e2; color: var(--red); }
.st-missed { background: #ffedd5; color: var(--orange); }

/* 卡片與列表 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.alert { padding: 12px 14px; border-radius: var(--r); margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; }
.alert.red { background: #fef2f2; border: 1px solid #fecaca; color: #7f1d1d; }
.alert.amber { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; }
.alert.blue { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a8a; }
.section-title { font-size: 13px; font-weight: 700; color: var(--ink-2); margin: 24px 0 8px; display: flex; align-items: center; gap: 8px; }
.section-title:first-child { margin-top: 0; }
.list { display: flex; flex-direction: column; }
.item { display: grid; grid-template-columns: 112px 64px 1fr auto; gap: 14px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer; background: #fff; }
.item:first-child { border-radius: var(--r) var(--r) 0 0; }
.item:last-child { border-bottom: 0; border-radius: 0 0 var(--r) var(--r); }
.item:only-child { border-radius: var(--r); }
.item:hover { background: #fafafb; }
.item .when { font-variant-numeric: tabular-nums; }
.item .when b { display: block; font-size: 14px; }
.item .when small { color: var(--ink-3); font-size: 12px; }
.thumb { width: 64px; height: 64px; border-radius: 8px; background: #eceef1 center/cover no-repeat; position: relative; overflow: hidden; display: grid; place-items: center; color: var(--ink-3); font-size: 11px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .count { position: absolute; right: 3px; bottom: 3px; background: rgba(0,0,0,.65); color: #fff; border-radius: 5px; font-size: 11px; padding: 0 5px; }
.thumb.video::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; background: rgba(0,0,0,.35); font-size: 18px; }
.item .text { min-width: 0; }
.item .text .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .text .t2 { color: var(--ink-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--line-2); color: var(--ink-2); margin-right: 6px; font-weight: 500; }
.empty { padding: 40px; text-align: center; color: var(--ink-3); }

/* 月曆 */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-head b { font-size: 16px; min-width: 110px; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-left: 1px solid var(--line); border-top: 1px solid var(--line); background: #fff; border-radius: var(--r); overflow: hidden; }
.cal .dow { padding: 6px 8px; font-size: 12px; color: var(--ink-3); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fafafb; }
.cal .day { min-width: 0; min-height: 112px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); position: relative; }
.cal .day.out { background: #fafafb; }
.cal .day.out .d { color: #c4c4c9; }
.cal .day.today .d { background: var(--accent); color: #fff; }
.cal .d { font-size: 12px; font-weight: 600; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 4px; }
.cal .add { position: absolute; top: 4px; right: 4px; opacity: 0; border: 0; background: var(--line-2); border-radius: 6px; width: 22px; height: 22px; cursor: pointer; }
.cal .day:hover .add { opacity: 1; }
.cal .ev { display: block; width: 100%; text-align: left; border: 0; border-left: 3px solid; border-radius: 4px; padding: 2px 6px; margin-bottom: 3px; font-size: 12px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.st-draft { border-color: var(--gray); } .ev.st-scheduled { border-color: var(--blue); } .ev.st-sent { border-color: var(--green); }
.ev.st-failed { border-color: var(--red); } .ev.st-missed { border-color: var(--orange); } .ev.st-sending { border-color: var(--amber); }

/* 編輯視窗 */
.overlay { position: fixed; inset: 0; background: rgba(15,15,20,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 24px; overflow-y: auto; }
.dialog { background: #fff; border-radius: 14px; width: 100%; max-width: 440px; box-shadow: 0 20px 60px rgba(0,0,0,.25); margin-top: 10vh; }
.dialog .body { padding: 22px 22px 8px; }
.dialog h3 { margin: 0 0 8px; font-size: 17px; }
.dialog .foot { padding: 14px 22px 20px; display: flex; justify-content: flex-end; gap: 8px; }
.editor { background: #fff; border-radius: 14px; width: 100%; max-width: 1180px; box-shadow: 0 20px 60px rgba(0,0,0,.25); display: flex; flex-direction: column; }
.editor .ehead { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.editor .ehead h3 { margin: 0; font-size: 17px; }
.editor .ehead .x { margin-left: auto; }
.editor .ebody { display: grid; grid-template-columns: minmax(0, 1fr) 380px; }
.editor .form { padding: 20px; display: flex; flex-direction: column; gap: 16px; border-right: 1px solid var(--line); }
.editor .side { padding: 20px; background: var(--tg-bg); display: flex; flex-direction: column; gap: 12px; }
.editor .efoot { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); align-items: center; flex-wrap: wrap; position: sticky; bottom: 0; background: #fff; border-radius: 0 0 14px 14px; }
.editor .efoot .sp { flex: 1; }
.counter { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-3); }
.counter.over { color: var(--red); font-weight: 700; }
.cap-head { display: flex; align-items: baseline; justify-content: space-between; }
.media-list { display: flex; flex-direction: column; gap: 6px; }
.mrow { display: grid; grid-template-columns: 20px 44px 1fr 92px auto; gap: 8px; align-items: center; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.mrow.drag-over { border-color: var(--blue); background: #eff6ff; }
.mrow .grip { cursor: grab; color: var(--ink-3); text-align: center; user-select: none; }
.mrow .thumb { width: 44px; height: 44px; border-radius: 6px; }
.mrow .src { font-size: 12px; color: var(--ink-2); word-break: break-all; line-height: 1.35; max-height: 34px; overflow: hidden; }
.mrow .src .badge { font-size: 10px; background: var(--line-2); padding: 0 5px; border-radius: 4px; margin-right: 4px; color: var(--ink-2); }
.mrow select { height: 30px; font-size: 12px; }
.mrow .acts { display: flex; gap: 2px; }
.mrow .acts button { width: 28px; height: 28px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.mrow .acts button:hover { background: var(--line-2); }
.mrow.uploading { opacity: .6; }
.drop { border: 1.5px dashed #c9cad0; border-radius: 10px; padding: 14px; text-align: center; color: var(--ink-3); cursor: pointer; background: #fcfcfd; }
.drop.over { border-color: var(--blue); background: #eff6ff; color: var(--blue); }
.add-urls { display: flex; gap: 8px; align-items: flex-start; }
.add-urls textarea { flex: 1; height: 38px; min-height: 38px; }
.readonly-banner { background: #f0fdf4; border: 1px solid #bbf7d0; color: #14532d; padding: 10px 12px; border-radius: 8px; }

/* Telegram 預覽 */
.tg-title { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.tg-bubble { background: #fff; border-radius: 12px 12px 12px 4px; overflow: hidden; box-shadow: 0 1px 1px rgba(0,0,0,.08); max-width: 340px; }
.tg-grid { display: grid; gap: 2px; background: #fff; }
.tg-grid .cell { background: #dde3ea center/cover no-repeat; aspect-ratio: 1; position: relative; overflow: hidden; }
.tg-grid .cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tg-grid .cell.video::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 22px; background: rgba(0,0,0,.3); }
.tg-grid .cell.span2 { grid-column: span 2; aspect-ratio: 2; }
.tg-cap { padding: 8px 10px 6px; white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.45; }
.tg-cap a { color: var(--tg); text-decoration: none; }
.tg-cap blockquote { margin: 4px 0; padding: 2px 8px; border-left: 3px solid var(--tg); background: #eef6fd; border-radius: 4px; }
.tg-cap code { background: #f1f1f4; padding: 0 3px; border-radius: 3px; }
.tg-time { text-align: right; font-size: 11px; color: var(--ink-3); padding: 0 10px 6px; }
.tg-note { font-size: 12px; color: var(--ink-2); background: rgba(255,255,255,.6); padding: 6px 10px; border-radius: 8px; }
.logs-mini { font-size: 12px; }
.logs-mini div { padding: 4px 0; border-top: 1px solid rgba(0,0,0,.06); }

/* 表格 */
table.tbl { width: 100%; border-collapse: collapse; background: #fff; }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.tbl th { font-size: 12px; color: var(--ink-3); font-weight: 600; background: #fafafb; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .detail { max-width: 420px; color: var(--ink-2); font-size: 13px; word-break: break-word; }
.settings { display: flex; flex-direction: column; gap: 20px; max-width: 900px; }
.settings .card { padding: 20px; }
.settings h3 { margin: 0 0 4px; font-size: 16px; }
.settings .desc { color: var(--ink-2); margin: 0 0 14px; font-size: 13px; }
.switch { position: relative; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d4d4d8; border-radius: 99px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(20px); }
.toggle-row { display: flex; align-items: center; gap: 12px; }

/* Toast */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 560px; }
.toast.err { background: var(--red); }

@media (max-width: 900px) {
  .editor .ebody { grid-template-columns: 1fr; }
  .editor .form { border-right: 0; }
  header.top { gap: 10px; padding: 0 12px; overflow-x: auto; }
  header.top .who { display: none; }
  .item { grid-template-columns: 64px 1fr; }
  .item .when { grid-column: 1 / -1; }
  .item .meta { grid-column: 1 / -1; flex-direction: row; align-items: center; }
  .cal .day { min-height: 70px; }
  .cal .ev { font-size: 10px; padding: 1px 3px; }
  .mrow { grid-template-columns: 16px 40px 1fr auto; }
  .mrow select { grid-column: 3; }
}

/* ── 多平台版面 ── */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side-nav { background: var(--ink); color: #d4d4d8; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 12px; gap: 16px; }
.side-nav .brand { color: #fff; font-weight: 700; padding: 0 8px; letter-spacing: .02em; }
.side-nav .brand span { color: #ff5470; }
.side-nav nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav nav a { color: #c9c9ce; text-decoration: none; padding: 8px 10px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.side-nav nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
.side-nav nav a:hover { background: #26262b; color: #fff; }
.side-nav nav a.on { background: #2f2f36; color: #fff; box-shadow: inset 3px 0 0 #ff5470; }
.nav-sep { font-size: 11px; color: #77777f; padding: 12px 10px 4px; letter-spacing: .05em; }
.platform-legend { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 0 8px; font-size: 12px; }
.platform-legend div { display: flex; align-items: center; gap: 8px; }
.platform-legend small { color: #77777f; margin-left: auto; }
.side-foot { border-top: 1px solid #2f2f36; padding: 12px 8px 0; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.side-foot .who { font-size: 13px; }
.side-foot .btn.ghost { color: #c9c9ce; padding: 0; height: auto; }
.layout main { max-width: 1240px; width: 100%; padding: 24px 28px 80px; margin: 0; }
.pb { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 18px; padding: 0 5px; border-radius: 5px; font-size: 10px; font-weight: 800; letter-spacing: .02em; line-height: 1; vertical-align: middle; flex: none; }
.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.chip .pb { margin-right: 2px; }
.item { grid-template-columns: 112px 64px 1fr minmax(180px, auto); }
.item .targets { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.tchip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 8px 2px 3px; border-radius: 6px; white-space: nowrap; }
.tchip b { font-weight: 600; }
.tchip.st-draft { background: #f1f1f4; color: var(--gray); } .tchip.st-scheduled { background: #e0ebff; color: var(--blue); }
.tchip.st-sent { background: #dcfce7; color: var(--green); } .tchip.st-failed { background: #fee2e2; color: var(--red); }
.tchip.st-missed { background: #ffedd5; color: var(--orange); } .tchip.st-sending { background: #fef3c7; color: var(--amber); }
.cal .ev { display: flex; align-items: center; gap: 4px; background: #f6f7f9; color: var(--ink); }
.cal .ev .pb { min-width: 18px; height: 14px; font-size: 8px; padding: 0 3px; }
.cal .ev.st-sent { background: #f0fdf4; } .cal .ev.st-failed { background: #fef2f2; } .cal .ev.st-missed { background: #fff7ed; } .cal .ev.st-scheduled { background: #eff6ff; }
.block-title { font-weight: 700; font-size: 14px; display: flex; align-items: baseline; gap: 8px; }
.block-title small { font-weight: 400; color: var(--ink-3); font-size: 12px; }
#counters span { margin-left: 6px; } #counters span.over { color: var(--red); font-weight: 700; }
.ptabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.ptab { border: 1px solid transparent; border-bottom: 0; background: transparent; padding: 8px 12px; border-radius: 8px 8px 0 0; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; color: var(--ink-2); margin-bottom: -1px; }
.ptab.on { background: #fff; border-color: var(--line); color: var(--ink); font-weight: 600; }
.ptab.soon { opacity: .6; }
.ptab small { font-size: 11px; color: var(--ink-3); }
.ptab .dot { font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: inline-grid; place-items: center; padding: 0 5px; }
.dot.st-draft { background: #e5e7eb; color: var(--gray); } .dot.st-scheduled { background: var(--blue); color: #fff; } .dot.st-sent { background: var(--green); color: #fff; }
.dot.st-failed { background: var(--red); color: #fff; } .dot.st-missed { background: var(--orange); color: #fff; } .dot.st-sending { background: var(--amber); color: #fff; }
.ppanel { border: 1px solid var(--line); border-top: 0; border-radius: 0 0 10px 10px; padding: 14px; background: #fff; }
.trows { display: flex; flex-direction: column; gap: 6px; }
.trow { display: grid; grid-template-columns: minmax(140px, 1fr) 150px 124px 70px auto; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.trow.on { border-color: #c7d7fe; background: #f8faff; }
.trow .tnote { grid-column: 1 / -1; font-size: 12px; }
.trow .tnote.ok { color: var(--green); } .trow .tnote.err { color: var(--red); }
.tcheck { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-size: 13px; }
.tcheck small { color: var(--ink-3); }
.soon-box { background: #fafafb; border: 1px dashed var(--line); border-radius: 10px; padding: 14px; color: var(--ink-2); }
.soon-box p { margin: 8px 0 0; }
.pcard h3 { display: flex; align-items: center; gap: 8px; }
.pcard.soon { opacity: .75; }
.logs-mini .pb { min-width: 18px; height: 14px; font-size: 8px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side-nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side-nav nav { flex-direction: row; flex-wrap: wrap; }
  .platform-legend, .nav-sep { display: none; }
  .side-foot { border: 0; padding: 0; flex-direction: row; align-items: center; margin-left: auto; }
  .layout main { padding: 16px; }
  .item { grid-template-columns: 64px 1fr; }
  .item .targets { grid-column: 1 / -1; align-items: flex-start; }
  .trow { grid-template-columns: 1fr 1fr; }
}
