:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1d20;
  --muted: #6b6d74;
  --line: #e4e2dc;
  --accent: #2f6fdf;
  --unread: #2f6fdf;
  --high: #c77700;
  --urgent: #d0342c;
  --ok: #2e8b57;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b;
    --surface: #212226;
    --text: #ecebe8;
    --muted: #9a9ba1;
    --line: #2f3035;
    --accent: #6d9cf0;
    --unread: #6d9cf0;
    --high: #e8a33d;
    --urgent: #f0645c;
    --ok: #5cc28a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button {
  font: inherit;
  font-size: 15px;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 6px 4px;
  cursor: pointer;
}
button:disabled { color: var(--muted); cursor: default; }

header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 8px;
  background: var(--bg);
}
header, .bar { max-width: 720px; margin: 0 auto; }
h1 { font-size: 28px; margin: 0; flex: 1; letter-spacing: -0.01em; }

#status {
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
#status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
#status[data-state="connected"]::before { background: var(--ok); }
#status[data-state="waiting"]::before,
#status[data-state="connecting"]::before { background: var(--high); }
#status[data-state="error"]::before { background: var(--urgent); }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 8px;
  color: var(--muted);
  font-size: 14px;
}

.notice {
  max-width: 696px;
  margin: 0 auto 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--high) 16%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--high) 45%, transparent);
  font-size: 14px;
  cursor: pointer;
}
@media (max-width: 720px) { .notice { margin: 0 12px 10px; } }
.body a + a { margin-left: 14px; }

main { padding: 0 12px 24px; max-width: 720px; margin: 0 auto; }
#list { list-style: none; margin: 0; padding: 0; }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; }

.msg {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--line);
  cursor: default;
  position: relative;
}
.msg.unread::after {
  content: "";
  position: absolute;
  top: 16px;
  right: 12px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--unread);
}
.icon { font-size: 22px; line-height: 1.2; width: 28px; text-align: center; flex: none; color: var(--muted); }
.body { min-width: 0; flex: 1; }
.head { display: flex; gap: 8px; align-items: baseline; padding-right: 16px; }
.title { flex: 1; font-weight: 500; overflow-wrap: anywhere; }
.unread .title { font-weight: 650; }
time { color: var(--muted); font-size: 13px; flex: none; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); margin-top: 2px; }
.msg:not(.unread) .text { color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.meta:empty { display: none; }
.body a { display: inline-block; margin-top: 6px; color: var(--accent); font-size: 14px; text-decoration: none; }
.resolved { opacity: 0.6; }
.resolved .text { color: var(--muted); }
.history { list-style: none; margin: 8px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.history li { display: flex; gap: 10px; padding: 2px 0; }
.history time { min-width: 48px; }
.history span { overflow-wrap: anywhere; }
.p4 { border-left: 3px solid var(--high); }
.p5 { border-left: 3px solid var(--urgent); }

dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog h3 { margin: 18px 0 6px; font-size: 15px; color: var(--muted); font-weight: 600; }
label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
label small { font-size: 12px; }
input {
  display: block;
  width: 100%;
  margin-top: 4px;
  font: inherit;
  font-size: 16px; /* stops iOS zooming on focus */
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
.topics { font-size: 14px; }
.topic { display: flex; align-items: baseline; gap: 10px; margin: 0; padding: 5px 0; color: var(--text); border-bottom: 1px solid var(--line); }
.topic span:first-child { flex: 1; overflow-wrap: anywhere; }
.topic small { color: var(--muted); }
.topic.off { color: var(--muted); }
.topic .sound { color: var(--muted); font-size: 13px; white-space: nowrap; }
.topic input { display: inline; width: auto; margin: 0 4px 0 0; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 14px; }
dt { color: var(--muted); }
dd { margin: 0; }
dd button { padding: 0 4px; }
details { margin-top: 14px; font-size: 14px; }
summary { color: var(--muted); cursor: pointer; }
#log {
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  border-radius: 8px;
  padding: 8px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
}
.actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.spacer { flex: 1; }
.primary { background: var(--accent); color: #fff; border-radius: 10px; padding: 7px 16px; }
.danger { color: var(--urgent); font-size: 14px; }
