:root {
  color-scheme: light dark;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #172033;
  --muted: #6d7687;
  --line: #e3e7ef;
  --accent: #3c63e8;
  --accent-soft: #e9edff;
  --danger: #c13b4c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root { --bg: #10131a; --surface: #191e28; --text: #edf1f8; --muted: #9da7b8; --line: #2a3240; --accent-soft: #252f5c; }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
.shell { width: min(780px, 100%); margin: 0 auto; padding: 28px 18px 60px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.text-button { padding: 8px 10px; color: var(--muted); background: transparent; font-size: 13px; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .18em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(28px, 7vw, 42px); letter-spacing: -.04em; }
h2 { font-size: 20px; }
.subtitle { margin-bottom: 0; color: var(--muted); }
.card { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: 0 8px 30px rgba(26, 37, 66, .05); }
.setup { max-width: 460px; padding: 22px; }
.setup p { color: var(--muted); line-height: 1.6; }
label { display: grid; gap: 8px; margin: 14px 0; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 12px 13px; background: var(--surface); color: var(--text); font: inherit; }
textarea { resize: vertical; }
select { min-height: 46px; cursor: pointer; appearance: auto; }
select option { background: var(--surface); color: var(--text); }
button { border: 0; border-radius: 11px; padding: 11px 16px; color: var(--text); background: var(--line); font: inherit; font-weight: 700; cursor: pointer; }
button:hover { filter: brightness(.96); }
.primary { width: 100%; color: #fff; background: var(--accent); }
.icon-button { width: 44px; height: 44px; padding: 0; font-size: 25px; color: var(--accent); background: var(--accent-soft); }
.error { min-height: 20px; margin: 12px 0 0; color: var(--danger) !important; }
.toolbar { padding: 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; }
.chip { flex: 0 0 auto; border-radius: 999px; padding: 8px 13px; color: var(--muted); background: transparent; }
.chip.active { color: var(--accent); background: var(--accent-soft); }
.search-row { display: flex; align-items: center; gap: 12px; }
.search-row input { flex: 1; }
.unread { display: flex; align-items: center; grid-template-columns: auto 1fr; gap: 6px; margin: 0; white-space: nowrap; color: var(--muted); font-weight: 500; }
.unread input { width: auto; }
.status { min-height: 27px; padding: 16px 4px 6px; color: var(--muted); font-size: 13px; }
.messages { display: grid; gap: 12px; }
.message { padding: 17px; }
.message-head, .message-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.source { font-weight: 800; }
.device { color: var(--accent); font-size: 13px; font-weight: 700; }
.time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.body { margin: 13px 0 16px; white-space: pre-wrap; line-height: 1.65; overflow-wrap: anywhere; }
.code { display: inline-flex; align-items: center; gap: 8px; color: var(--accent); background: var(--accent-soft); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.admin-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.4fr) minmax(260px, .8fr); }
.panel-card { padding: 20px; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 14px; }
.panel-heading > div { min-width: 0; }
.panel-heading > button { flex: 0 0 auto; min-width: 98px; padding: 10px 12px; font-size: 14px; white-space: nowrap; }
.panel-heading p, .panel-card > p { color: var(--muted); line-height: 1.5; }
.device-list { display: grid; gap: 10px; margin-top: 18px; }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; border-top: 1px solid var(--line); }
.device-row div:first-child { display: grid; gap: 5px; min-width: 0; }
.device-row span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.device-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: end; }
.device-actions button { padding: 7px 9px; font-size: 12px; }
.device-state { color: var(--danger) !important; }
.device-state.on { color: #29945b !important; }
.toggle { display: flex; align-items: center; grid-template-columns: auto 1fr; gap: 8px; font-weight: 500; }
.toggle input { width: auto; }
.device-dialog { border: 0; padding: 0; background: transparent; color: var(--text); width: min(460px, calc(100% - 28px)); }
.device-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-card { padding: 22px; }
.dialog-actions { display: flex; justify-content: end; gap: 8px; margin-top: 18px; }
@media (max-width: 700px) { .admin-grid { grid-template-columns: 1fr; } .device-row { align-items: start; flex-direction: column; } .device-actions { justify-content: start; } }
@media (max-width: 560px) { .shell { padding-top: 20px; } .search-row { align-items: stretch; flex-direction: column; gap: 4px; } .unread { align-self: flex-start; } }
