:root {
  --bg: #0b141a; --panel: #111b21; --panel2: #202c33; --text: #e9edef; --muted: #8696a0;
  --me: #005c4b; --them: #202c33; --accent: #00a884; --danger: #d9534f; --line: #2a3942;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; border-radius: 8px;
  background: var(--accent); padding: 10px 14px; }
button.icon { background: transparent; font-size: 24px; padding: 4px 10px; }
button.small { padding: 6px 10px; font-size: 13px; }
button.danger { background: var(--danger); }
button.secondary { background: var(--panel2); }
button:disabled { opacity: .5; }
input, textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; width: 100%; }
.hidden { display: none !important; }
#app { height: 100%; max-width: 900px; margin: 0 auto; }
.view { height: 100%; display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); }
.bar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .title { flex: 1; min-width: 0; }
.bar .title h1 { font-size: 17px; }
.sub { font-size: 12px; color: var(--muted); }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.card { background: var(--panel); border-radius: 12px; padding: 20px; }
.login { margin: 12vh auto 0; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login h1 { margin: 0 0 8px; font-size: 20px; }
.logo { width: 64px; height: 64px; margin: 0 auto; }
.error { color: #ff8a80; min-height: 1em; margin: 0; }
.menu { position: absolute; right: 12px; top: 54px; z-index: 5; background: var(--panel2); border-radius: 10px;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 6px 24px #0008; }
.menu button { background: transparent; text-align: left; border-radius: 0; padding: 12px 18px; }
.menu button:hover { background: var(--line); }
.device-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 6px; color: var(--muted);
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #555; flex: none; }
.dot.on { background: var(--accent); }
.dot.inline { display: inline-block; margin-right: 6px; }
.dot.working { background: #f0b429; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.inst { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.inst:hover { background: var(--panel); }
.inst .avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--panel2); flex: none;
  display: grid; place-items: center; font-weight: 600; color: var(--accent); }
.inst .body { flex: 1; min-width: 0; }
.inst .row1 { display: flex; justify-content: space-between; gap: 8px; }
.inst .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inst .time { font-size: 12px; color: var(--muted); flex: none; }
.inst .snippet { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inst.offline { opacity: .5; }
.inst.working { background: #f0b42914; box-shadow: inset 4px 0 0 #f0b429; }
.inst.working .avatar { color: #f0b429; box-shadow: 0 0 0 2px #f0b429; animation: pulse 1.6s infinite; }
.inst.working .state { color: #f0b429; font-weight: 600; }
#chat-sub.working { color: #f0b429; font-weight: 600; }
.working-bubble { align-self: flex-start; background: #f0b42922; color: #f0b429; border: 1px solid #f0b42955;
  padding: 6px 12px; border-radius: 14px; font-size: 13px; display: flex; align-items: center; gap: 3px; }
.working-bubble span { width: 6px; height: 6px; border-radius: 50%; background: #f0b429; animation: pulse 1.2s infinite; }
.working-bubble span:nth-child(2) { animation-delay: .2s; }
.working-bubble span:nth-child(3) { animation-delay: .4s; margin-right: 4px; }
.msg .thumb { display: block; max-width: 220px; max-height: 220px; border-radius: 6px; margin-bottom: 4px; }
.attach-strip { display: flex; gap: 8px; padding: 8px 8px 0; background: var(--panel); overflow-x: auto; }
.attach-strip .att { position: relative; flex: none; }
.attach-strip img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; display: block; }
.attach-strip button { position: absolute; top: -4px; right: -4px; width: 22px; height: 22px; padding: 0;
  border-radius: 50%; font-size: 12px; background: var(--danger); }
.attach-btn { width: 44px; height: 44px; flex: none; display: grid; place-items: center; font-size: 22px;
  border-radius: 50%; background: var(--panel2); cursor: pointer; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: #f0b42933; color: #f0b429; margin-left: 6px; }
.empty { color: var(--muted); padding: 16px 14px; font-size: 14px; }
#messages { padding: 10px 10px 4px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 85%; padding: 7px 10px 5px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word;
  overflow-wrap: anywhere; }
.msg.them { background: var(--them); align-self: flex-start; border-top-left-radius: 2px; }
.msg.me { background: var(--me); align-self: flex-end; border-top-right-radius: 2px; }
.msg.err { background: #4a1d1d; align-self: flex-start; }
.msg .meta { font-size: 11px; color: #ffffff88; text-align: right; margin-top: 2px; }
.msg pre { background: #0006; padding: 8px; border-radius: 6px; overflow-x: auto; white-space: pre; margin: 4px 0; }
.msg code { background: #0004; padding: 0 3px; border-radius: 3px; }
.msg a { color: #53bdeb; }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 3px 10px; border-radius: 8px; }
.tools { align-self: flex-start; max-width: 92%; font-size: 12px; color: var(--muted); }
.tools summary { cursor: pointer; padding: 2px 4px; }
.tools div { font-family: ui-monospace, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere;
  padding: 3px 6px; border-left: 2px solid var(--line); margin: 2px 0 2px 8px; }
.older { align-self: center; }
#composer { display: flex; gap: 8px; padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--panel); align-items: flex-end; }
#composer textarea { resize: none; max-height: 40vh; border-radius: 20px; }
#composer button { border-radius: 50%; width: 44px; height: 44px; padding: 0; flex: none; font-size: 18px; }
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 10; padding: 16px; }
.modal .card { max-width: 420px; width: 100%; display: flex; flex-direction: column; gap: 12px; }
.modal h2 { margin: 0; font-size: 18px; }
.code { font: 600 28px ui-monospace, Consolas, monospace; letter-spacing: .15em; text-align: center;
  background: var(--panel2); padding: 12px; border-radius: 8px; }
.dev-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.dev-row span { flex: 1; }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: var(--panel2);
  padding: 10px 16px; border-radius: 10px; z-index: 20; box-shadow: 0 4px 16px #0008; max-width: 90%; }
