:root {
  --bg: #0f1115; --panel: #171a21; --line: #262b36;
  --fg: #e6e8ee; --muted: #8b93a7; --accent: #4c8dff;
  --danger: #e5484d; --ok: #30a46c;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--fg); }
#app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }

#sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 12px; overflow: auto; }
.brand { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.field-label { font-size: 12px; color: var(--muted); }
select, input[type=search], input[type=text], input:not([type]) { width: 100%; padding: 7px 9px; background: #10131a; color: var(--fg); border: 1px solid var(--line); border-radius: 7px; }
#kindTabs { display: flex; flex-direction: column; gap: 4px; }
#kindTabs button { text-align: left; padding: 8px 10px; background: transparent; color: var(--fg); border: 1px solid transparent; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#kindTabs button.active { background: #1f2634; border-color: var(--line); }
.badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; min-width: 20px; text-align: center; }
.badge:empty { display: none; }
.device-list { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.device-row { display: flex; justify-content: space-between; gap: 8px; padding: 5px 8px; border-radius: 6px; background: #13161d; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
button { cursor: pointer; padding: 7px 11px; border-radius: 7px; border: 1px solid var(--line); background: #1f2634; color: var(--fg); }
button:hover { border-color: var(--accent); }
button.danger { background: #3a1d1f; border-color: #5b2a2d; color: #ffb3b5; }

#main { display: flex; flex-direction: column; min-width: 0; }
#toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
#toolbar input[type=search] { flex: 1; }
#toolbar select { width: auto; }
.chk { display: flex; align-items: center; gap: 5px; color: var(--muted); white-space: nowrap; }
.chk input { width: auto; }

#list { flex: 1; overflow: auto; padding: 8px 14px 90px; }
.msg { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; padding: 10px; border-bottom: 1px solid var(--line); align-items: start; }
.msg.unread { background: #141a25; }
.msg.fresh { animation: hl 3s ease-out; }
@keyframes hl { from { background: #24405f; } to { background: transparent; } }
.msg .icon { font-size: 17px; text-align: center; }
.msg .content { min-width: 0; }
.msg .top { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.msg .who { font-weight: 600; }
.msg .app { color: var(--accent); font-size: 12px; }
.msg .dev { color: var(--muted); font-size: 11px; }
.msg .body { color: #c9cede; white-space: pre-wrap; word-break: break-word; margin-top: 3px; }
.msg .time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.msg .row-actions { margin-top: 6px; display: flex; gap: 6px; }
.msg .row-actions button { padding: 3px 8px; font-size: 12px; }
input.pick { width: auto; margin-top: 3px; }
.empty { color: var(--muted); text-align: center; padding: 40px; }

#bulk { position: fixed; left: 260px; right: 0; bottom: 0; display: flex; gap: 10px; align-items: center;
  padding: 10px 16px; background: #1b2230; border-top: 1px solid var(--line); }
#bulk[hidden] { display: none; }

dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--fg); padding: 18px; max-width: 640px; width: 90%; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog label { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--muted); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin-top: 14px; }
.hint { color: var(--muted); font-size: 12px; }

.device-card { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; margin: 10px 0; }
.device-card-title { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.key-row { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
code { background: #10131a; padding: 2px 6px; border-radius: 5px; font-family: ui-monospace, monospace; }
.key-once { display: block; padding: 10px; margin: 8px 0; word-break: break-all; font-size: 15px; }

#toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: #2b3448;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); z-index: 99; }
#toast[hidden] { display: none; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { flex-direction: row; align-items: center; overflow-x: auto; }
  #kindTabs { flex-direction: row; }
  .device-list, .brand, .field-label { display: none; }
  #bulk { left: 0; }
}
