:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --mine: #dbeafe;
  --error: #b91c1c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --panel: #1a1d23;
    --text: #e6e8eb;
    --muted: #8b93a1;
    --border: #2a2e36;
    --accent: #3b82f6;
    --mine: #1e3a5f;
    --error: #f87171;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }

input, button {
  font: inherit;
  color: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}
button {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }

.card {
  max-width: 360px;
  margin: 12vh auto 0;
  padding: 24px 16px;
}
.card h1 { margin: 0 0 16px; font-size: 1.4rem; }
.card form { display: grid; gap: 12px; }
.card label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.error { color: var(--error); margin: 0; min-height: 1.4em; }

#chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--panel);
  border-inline: 1px solid var(--border);
}
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.status { font-size: .8rem; color: var(--muted); }
.online { margin-left: auto; font-size: .8rem; color: var(--muted); text-align: right; }
#alerts-btn { padding: 6px 8px; }
#alerts-btn[aria-pressed="true"] { border-color: var(--accent); }

#messages {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 12px 16px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; background: var(--bg); overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg .meta { font-size: .75rem; color: var(--muted); margin-bottom: 2px; }
.msg .body { white-space: pre-wrap; }
.sys { align-self: center; font-size: .8rem; color: var(--muted); }

#send-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
#send-form input { flex: 1; min-width: 0; }

button.icon {
  background: var(--bg);
  color: inherit;
  border-color: var(--border);
  padding: 10px;
  line-height: 1;
}

.msg.bare { background: none; padding: 0 4px; }
.msg.bare .meta { margin-bottom: 0; }
.big { font-size: 3rem; line-height: 1.1; }
.msg img.pic {
  display: block;
  max-width: min(100%, 360px);
  max-height: 360px;
  border-radius: 8px;
  margin: 2px 0;
}
.msg img.sticker { display: block; width: 140px; height: 140px; object-fit: contain; }
.msg a { display: block; }

.notice {
  margin: 0 16px 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg);
  font-size: .9rem;
}

#panel { border-top: 1px solid var(--border); max-height: 260px; overflow-y: auto; padding: 8px 12px; }
.panel-bar { display: flex; gap: 6px; margin-bottom: 8px; }
.tab {
  background: var(--bg);
  color: inherit;
  border-color: var(--border);
  padding: 6px 12px;
  font-size: .9rem;
}
.tab.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.tab.edit { margin-left: auto; }
.cats { display: flex; gap: 4px; margin-bottom: 6px; }
.cats button, .grid button {
  background: none;
  color: inherit;
  border-color: transparent;
  padding: 4px;
  font-size: 1.4rem;
  line-height: 1.2;
}
.cats button.active { background: var(--bg); border-color: var(--border); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px; }
.grid.stickers { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.grid.stickers button { font-size: 2.4rem; }
.grid.stickers .tile { position: relative; }
.grid.stickers .tile img { width: 100%; height: 72px; object-fit: contain; display: block; }
.grid.stickers .del {
  display: none;
  position: absolute;
  top: -4px;
  right: -4px;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  background: var(--error);
  color: #fff;
  font-size: 1rem;
}
.grid.stickers.editing .del { display: block; }
.add-tile { border: 2px dashed var(--border) !important; color: var(--muted) !important; height: 72px; }
.hint { color: var(--muted); font-size: .8rem; margin: 8px 0 0; }

.people {
  display: flex;
  gap: 8px;
  padding: 6px 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  font-size: .8rem;
}
.people:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip.off { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex: none; }
.chip.off .dot { background: var(--muted); opacity: .5; }

.typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 6px;
  font-size: .8rem;
  color: var(--muted);
}
.typing[hidden] { display: none; }
.dots { display: inline-flex; gap: 3px; }
.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.1s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; } }

.msg .seen { margin-top: 2px; font-size: .7rem; color: var(--muted); text-align: right; }
