:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --line: #e7e6e2;
  --line-strong: #d6d4ce;
  --text: #1d1c1a;
  --muted: #8a877f;
  --accent: #ff3b47;
  --accent-soft: #fff0f1;
  --ok: #1f9d55;
  --warn: #c98a00;
  --err: #d93025;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #f1f0ec; padding: 1px 6px; border-radius: 5px; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--err); min-height: 1.2em; margin: 0; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }

/* buttons */
.btn { border: 1px solid var(--line-strong); background: var(--panel); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #bdbab2; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(.95); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { color: var(--err); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 320px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px; display: grid; gap: 14px; }
.login-card input { padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand.big { font-size: 22px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent) url("/favicon.svg") center/cover; }

/* top bar */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 28px; padding: 0 20px; height: 54px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tabs button.active { background: var(--bg); color: var(--text); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--ok); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.badge:empty { display: none; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.live.on { background: var(--ok); box-shadow: 0 0 0 3px #1f9d5522; }

main { padding: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 16px; }
.page-head h2 { margin: 0 0 4px; font-size: 20px; }
.page-head p { margin: 0; }

/* content split */
.split { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
.list-pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; position: sticky; top: 74px; max-height: calc(100vh - 94px); display: flex; flex-direction: column; }
.pane-head { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.pane-head input { flex: 1; min-width: 0; padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: 8px; }
.content-list { overflow: auto; }
.citem { display: grid; grid-template-columns: 52px 1fr; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.citem:hover { background: #fafaf8; }
.citem.active { background: var(--accent-soft); }
.citem .thumb { width: 52px; height: 52px; border-radius: 8px; background: #eeede9 center/cover; position: relative; display: grid; place-items: center; color: var(--muted); font-size: 18px; }
.citem .thumb .n { position: absolute; right: 3px; bottom: 3px; background: #0009; color: #fff; font-size: 10px; padding: 0 4px; border-radius: 4px; }
.citem .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.citem .s { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.citem .meta { color: var(--muted); font-size: 11px; margin-top: 4px; }
.list-empty { padding: 30px 16px; text-align: center; color: var(--muted); }

.editor { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 24px; min-height: 420px; }
.empty-state { display: grid; place-items: center; min-height: 380px; text-align: center; color: var(--muted); }
.empty-icon { font-size: 34px; }
.editor-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: 13px; }
.field em { font-style: normal; font-weight: 400; margin-left: 6px; font-size: 12px; }
.field input, .field textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; }
.field textarea { resize: vertical; line-height: 1.6; }
.field input:focus, .field textarea:focus { outline: 2px solid #ff3b4733; border-color: var(--accent); }
.count { color: var(--muted); }
.count.over { color: var(--err); font-weight: 600; }

.drop { border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 12px; transition: background .15s; }
.drop.hover { background: var(--accent-soft); border-color: var(--accent); }
.drop-cta { display: block; text-align: center; padding: 10px; color: var(--muted); cursor: pointer; }
.drop-cta u { color: var(--accent); text-decoration: none; }
.media-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.mtile { position: relative; width: 108px; height: 144px; border-radius: 8px; overflow: hidden; background: #eeede9; cursor: grab; }
.mtile img, .mtile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.mtile .idx { position: absolute; left: 5px; top: 5px; background: #000a; color: #fff; font-size: 11px; border-radius: 4px; padding: 0 5px; }
.mtile .kind { position: absolute; left: 5px; bottom: 5px; background: #000a; color: #fff; font-size: 10px; border-radius: 4px; padding: 0 5px; }
.mtile .x { position: absolute; right: 4px; top: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: #000a; color: #fff; cursor: pointer; line-height: 22px; padding: 0; }
.mtile.dragging { opacity: .4; }
.mtile.uploading { display: grid; place-items: center; cursor: default; font-size: 12px; color: var(--muted); }
.mtile .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); }

.send-box { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 16px; }
.send-title { font-weight: 700; margin-bottom: 12px; }
.send-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.send-row.top { align-items: flex-start; }
.send-label { width: 34px; color: var(--muted); flex: none; padding-top: 2px; }
.seg { display: inline-flex; background: var(--bg); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.seg button.on { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px #0001; }
.hint { margin: -2px 0 10px 46px; }
.device-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.dchip { display: flex; align-items: center; gap: 7px; border: 1px solid var(--line-strong); border-radius: 20px; padding: 6px 12px 6px 10px; cursor: pointer; user-select: none; }
.dchip.on { border-color: var(--accent); background: var(--accent-soft); }
.dchip input { display: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); flex: none; }
.dot.on { background: var(--ok); }
.send-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 6px; }
.mini-tasks { margin-top: 12px; display: grid; gap: 6px; }
.mini-task { display: flex; align-items: center; gap: 10px; font-size: 12px; padding: 7px 10px; background: var(--bg); border-radius: 8px; }
.mini-task .grow { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* status chip */
.st { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.st.run { background: #fff6e0; color: var(--warn); }
.st.ok { background: #e6f5ec; color: var(--ok); }
.st.bad { background: #fdecea; color: var(--err); }

/* devices */
.device-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.dcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 8px; }
.dcard .name { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.dcard .info { color: var(--muted); font-size: 12px; line-height: 1.7; }
.dcard .acts { display: flex; gap: 8px; margin-top: 4px; }

/* tasks table */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table.tasks { width: 100%; border-collapse: collapse; }
.tasks th, .tasks td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tasks th { font-weight: 600; color: var(--muted); font-size: 12px; background: #fbfbfa; }
.tasks td.detail { color: var(--muted); font-size: 12px; max-width: 360px; }
.tasks tr:last-child td { border-bottom: 0; }

/* dialog */
.dialog { border: 0; border-radius: 16px; padding: 24px; width: min(560px, 92vw); box-shadow: 0 20px 60px #0003; }
.dialog::backdrop { background: #0005; }
.dialog h3 { margin: 0 0 14px; }
.dialog-close { position: absolute; right: 16px; top: 16px; }
.pair-grid { display: grid; grid-template-columns: 200px 1fr; gap: 20px; align-items: start; }
.qr svg { width: 200px; height: 200px; display: block; }
.pair-steps { margin: 0; padding-left: 18px; line-height: 1.9; }
.code { font-size: 18px; letter-spacing: 3px; font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #1d1c1af0; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 50; max-width: 80vw; }

@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .list-pane { position: static; max-height: 320px; }
  .pair-grid { grid-template-columns: 1fr; }
}
