:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --fg: #e6e6e6;
  --muted: #8a8f9c;
  --accent: #7aa2f7;
  --accent-2: #bb9af7;
  --green: #9ece6a;
  --red: #f7768e;
  --yellow: #e0af68;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  max-width: 100vw;
}

dialog#join-modal {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  border-radius: 12px;
  padding: 24px;
  max-width: 340px;
  box-shadow: 0 16px 48px rgba(0,0,0,.6);
}
dialog#join-modal::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
dialog h1 { margin: 0 0 4px; font-size: 20px; }
dialog p { color: var(--muted); margin: 4px 0 12px; }
dialog input { width: 100%; }
dialog button { margin-top: 12px; }
.error { color: var(--red); font-size: 13px; }

input, select, button {
  font: inherit;
  color: var(--fg);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}
input:focus, select:focus, button:focus { outline: 1px solid var(--accent); }
button { cursor: pointer; }
button:hover { background: #262b35; }

#app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  grid-template-rows: 44px 1fr;
  grid-template-areas: "header header" "sidebar main";
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  overflow: hidden;
}
header {
  grid-area: header;
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
header .who { color: var(--muted); }
header strong { color: var(--accent); }
.grow { flex: 1; }

#sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 12px;
  overflow: auto;
}
#sidebar h2 { margin: 0 0 8px; }
#sidebar-toggle {
  display: flex; align-items: center; gap: 6px;
  width: 100%;
  padding: 4px 6px;
  background: none; border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  cursor: pointer;
  text-align: left;
}
#sidebar-toggle:hover { background: var(--panel-2); border-color: var(--border); }
#sidebar-toggle .chevron {
  display: inline-block;
  transition: transform 0.15s ease;
  font-size: 10px;
}
#sidebar.collapsed #sidebar-toggle .chevron { transform: rotate(-90deg); }
#sidebar-toggle .count {
  margin-left: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  text-transform: none;
}
#sidebar.collapsed #sidebar-body { display: none; }
#sidebar.collapsed { padding-bottom: 8px; }
#add-topic-form { display: flex; gap: 6px; margin-bottom: 10px; }
#add-topic-form input { flex: 1; min-width: 0; }
#topic-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#topic-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
}
#topic-list li .name { font-family: var(--mono); }
#topic-list li button { padding: 2px 8px; font-size: 12px; }

#stream-wrap {
  grid-area: main;
  display: flex; flex-direction: column;
  min-height: 0;
  min-width: 0;
}
#stream {
  list-style: none; margin: 0; padding: 12px;
  flex: 1; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0;
}
/* Chat & presence rows flow as inline text so the message wraps the
   full row width and continuation lines tuck under the prefixes. */
.row {
  padding: 4px 6px;
  border-radius: 4px;
  min-width: 0;
  word-break: break-word;
}
.row:hover { background: rgba(255,255,255,.02); }
.row .topic { font-family: var(--mono); color: var(--accent-2); font-size: 12px; }
.row .topic::before { content: "["; color: var(--muted); }
.row .topic::after  { content: "]"; color: var(--muted); }
.row .user { font-weight: 600; color: var(--green); }
.row .user::before { content: "<"; color: var(--muted); font-weight: 400; }
.row .user::after  { content: ">"; color: var(--muted); font-weight: 400; }
.row .text { word-break: break-word; }
.row .text a { color: var(--accent); }
.row .text img { display: block; max-width: min(420px, 100%); max-height: 320px; margin-top: 4px; border-radius: 6px; border: 1px solid var(--border); }
.row time { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

/* The 'other' (non-chat ntfy event) row keeps its card grid layout. */
.row.other {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
}
.row.other > * { min-width: 0; }
.row.other .card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--yellow);
  border-radius: 6px;
  padding: 6px 10px;
  background: var(--panel-2);
}
.row.other .card .title { font-weight: 600; color: var(--yellow); }
.row.other .card .title:empty { display: none; }
.row.other .card .message { white-space: pre-wrap; word-break: break-word; }
.row.other .card .message:empty { display: none; }
.row.other .card .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.row.other .card .meta:empty { display: none; }
.row.other .card .meta a { color: var(--accent); }
.row.other .card .tag {
  display: inline-block; margin-right: 4px; padding: 0 6px;
  border: 1px solid var(--border); border-radius: 999px; font-size: 11px;
}
.row.other .card .priority-5 { color: var(--red); }
.row.other .card .priority-4 { color: var(--yellow); }
.row.other .card .priority-1, .row.other .card .priority-2 { color: var(--muted); }

.row.system { color: var(--muted); font-style: italic; }

.row.presence {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
}

#send-form {
  display: flex; gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  min-width: 0;
}
#send-target { min-width: 0; max-width: 30%; flex: 0 1 auto; }
#send-input { flex: 1 1 0; min-width: 0; }

dialog#join-modal label {
  display: block;
  margin-top: 10px;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
dialog#join-modal .hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
dialog#join-modal code { font-family: var(--mono); color: var(--accent-2); }

dialog#install-help {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  border-radius: 12px;
  padding: 20px;
  max-width: 400px;
}
dialog#install-help::backdrop { background: rgba(0,0,0,.55); }
dialog#install-help h2 { margin: 0 0 8px; font-size: 16px; }
dialog#install-help p { margin: 8px 0; }
dialog#install-help button { margin-top: 10px; }

#install-btn { background: var(--accent); color: #0f1115; border-color: var(--accent); }
#install-btn:hover { filter: brightness(1.1); }
#install-help-btn { padding: 4px 10px; }

@media (max-width: 720px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "header" "sidebar" "main"; grid-template-rows: 44px auto 1fr; }
  #sidebar { max-height: 30dvh; }
  #send-form { flex-wrap: wrap; }
  #send-target { max-width: 40%; flex: 0 0 auto; order: 1; }
  #send-input { flex: 1 1 100%; order: 3; }
  #send-form button[type="submit"] { order: 2; flex: 0 0 auto; }
  header { padding: 0 8px; gap: 6px; }
  header .who { font-size: 12px; }
}
