:root {
  --bg: #0f1115; --bg2: #161a22; --bg3: #1e232e; --line: #2a303c;
  --fg: #e7e9ee; --muted: #8b93a5; --accent: #7c5cff; --accent2: #5fd3a0; --danger: #ff6b6b; --warn: #ffb454;
  --mine: #2a2452; --theirs: #1b2029; --sys: #161a22;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: #a99cff; }
code { background: var(--bg3); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
[hidden] { display: none !important; }

/* ---------- topo */
.top {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
  padding-top: max(8px, env(safe-area-inset-top));
}
.top h1 { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title { min-width: 0; flex: 0 1 auto; }
.presence { display: flex; gap: 10px; font-size: 12px; color: var(--muted); }
.presence .u::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #555; margin-right: 5px; }
.presence .u.on::before { background: var(--accent2); }
.icon-btn { background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; cursor: pointer; font-size: 18px; line-height: 1; }
.icon-btn:hover { background: var(--bg3); }
.icon-btn.on { color: var(--accent2); }
.only-mobile { display: none; }
.search-wrap { flex: 1; position: relative; min-width: 120px; }
.search-wrap input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.search-results {
  position: absolute; top: 40px; left: 0; right: 0; background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius); max-height: 60vh; overflow: auto; z-index: 30; box-shadow: 0 10px 30px #0008;
}
.search-results .r { padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px; }
.search-results .r:hover { background: var(--bg3); }
.search-results .r .who { color: var(--muted); font-size: 12px; }
.search-results mark { background: #5a4bcc; color: #fff; border-radius: 3px; padding: 0 2px; }
.search-results .empty { padding: 12px; color: var(--muted); }

/* ---------- layout */
.layout { flex: 1; display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.side { border-left: 1px solid var(--line); background: var(--bg2); overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 14px; }
.panel { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.panel.small p { margin: 0; font-size: 12px; }
.list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.list li { background: var(--bg3); border-radius: 8px; padding: 7px 9px; font-size: 14px; display: flex; gap: 8px; align-items: flex-start; }
.list li .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list li .sub { color: var(--muted); font-size: 12px; }
.list li.done .txt { text-decoration: line-through; color: var(--muted); }
.list li button { background: transparent; border: 0; cursor: pointer; color: var(--muted); padding: 0 2px; }
.list li button:hover { color: var(--fg); }
.list .empty { color: var(--muted); font-size: 13px; background: transparent; padding: 2px 0; }
.mini-form { display: flex; flex-direction: column; gap: 6px; }
.mini-form input { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.mini-form button, .primary { background: var(--accent); border: 0; border-radius: 8px; padding: 7px 12px; cursor: pointer; color: #fff; font-weight: 600; }
.mini-form button:hover, .primary:hover { filter: brightness(1.1); }

/* ---------- mensagens */
.pinned { background: #221d3f; border-bottom: 1px solid var(--line); padding: 6px 12px; display: flex; gap: 8px; overflow-x: auto; font-size: 13px; }
.pinned .p { background: var(--bg3); border-radius: 8px; padding: 4px 8px; white-space: nowrap; cursor: pointer; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; flex: 0 0 auto; }
.pinned .p:hover { background: var(--line); }
.status { background: var(--warn); color: #000; text-align: center; font-size: 13px; padding: 4px; }
.messages { flex: 1; overflow-y: auto; padding: 10px 14px; scroll-behavior: auto; }
.sentinel { height: 1px; }
.day { text-align: center; color: var(--muted); font-size: 12px; margin: 14px 0 8px; }
.day span { background: var(--bg2); padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); }
.msg { position: relative; max-width: min(78%, 720px); margin: 4px 0; padding: 7px 11px 6px; border-radius: var(--radius); background: var(--theirs); }
.msg.mine { margin-left: auto; background: var(--mine); }
.msg.system { max-width: 100%; margin: 6px auto; background: transparent; color: var(--muted); font-size: 13px; text-align: center; padding: 2px 8px; }
.msg.system .meta, .msg.system .actions { display: none; }
.msg.pinned-msg { outline: 1px solid #5a4bcc; }
.msg.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.meta { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.meta .author { font-weight: 600; color: #c9c1ff; }
.msg.mine .meta .author { color: #d6d0ff; }
.ticks { margin-left: auto; font-size: 11px; }
.ticks.seen { color: var(--accent2); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.body img.thumb { display: block; max-width: 100%; max-height: 360px; border-radius: 8px; margin-top: 4px; background: #000; }
.body .file { display: flex; align-items: center; gap: 8px; background: #0008; border-radius: 8px; padding: 8px 10px; margin-top: 4px; }
.body .file .name { font-weight: 600; overflow-wrap: anywhere; }
.body .file .size { color: var(--muted); font-size: 12px; }
.body video, .body audio { max-width: 100%; margin-top: 4px; border-radius: 8px; }
.body .caption { margin-top: 4px; }
.actions { position: absolute; top: -12px; right: 8px; display: none; gap: 2px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 1px; }
.msg:hover .actions, .msg:focus-within .actions { display: flex; }
.act { background: transparent; border: 0; cursor: pointer; font-size: 13px; padding: 2px 5px; border-radius: 6px; }
.act:hover { background: var(--bg3); }
.typing { height: 20px; padding: 0 16px; color: var(--muted); font-size: 12px; }
.jump { position: absolute; bottom: 86px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; border: 0; border-radius: 999px; padding: 6px 14px; cursor: pointer; box-shadow: 0 6px 20px #0008; }

/* ---------- compositor */
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--bg2); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.composer textarea { flex: 1; resize: none; max-height: 160px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.composer textarea:focus { outline: 1px solid var(--accent); }
.upload-progress { position: absolute; left: 12px; right: 12px; bottom: 64px; background: var(--bg3); border-radius: 8px; padding: 6px 10px; font-size: 12px; }
.upload-progress .bar { height: 4px; background: var(--accent); border-radius: 2px; width: 0; margin-bottom: 4px; transition: width .15s; }
.drop { position: absolute; inset: 0; background: #0f1115dd; border: 3px dashed var(--accent); border-radius: var(--radius); display: grid; place-items: center; font-size: 20px; z-index: 20; pointer-events: none; }
.overlay { position: fixed; inset: 0; background: #0009; z-index: 40; }

/* ---------- login */
.login-body { align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card h1 { font-size: 18px; margin: 4px 0 0; }
.login-card p { margin: 0; }
.login-card label { text-align: left; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; color: var(--fg); }
.login-card img { margin: 0 auto; }

/* ---------- telemóvel */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .side { position: fixed; top: 0; bottom: 0; right: 0; width: min(88vw, 360px); z-index: 50; transform: translateX(100%); transition: transform .2s; border-left: 1px solid var(--line); padding-top: max(12px, env(safe-area-inset-top)); }
  .side.open { transform: none; }
  .msg { max-width: 88%; }
  .top h1 { font-size: 15px; }
  .search-wrap { min-width: 80px; }
  .actions { display: flex; opacity: .85; }
}
