:root {
  --bg: #0e1621;
  --bg-2: #17212b;
  --bg-3: #1f2c39;
  --panel: #182533;
  --border: #243140;
  --accent: #2ea6ff;
  --accent-2: #246b9e;
  --text: #e9eef3;
  --muted: #7d8e9e;
  --me: #2b5278;
  --them: #1f2c39;
  --ok: #4dd06e;
  --err: #ff6b6b;
  --warn: #f3c969;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--err); margin: 8px 0 0; }
.warn { color: var(--warn); font-size: 12px; }

/* Botões */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06223a; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }

input, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 4px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
label { display: block; margin-top: 12px; font-size: 12px; color: var(--muted); }

/* Gate */
.gate { display: flex; align-items: center; justify-content: center; height: 100%; }
.gate-card {
  background: var(--panel); padding: 32px; border-radius: 14px;
  border: 1px solid var(--border); width: 360px; text-align: center;
}
.gate-card h1 { margin: 0 0 6px; }
.gate-card input { margin: 16px 0; }
.gate-card .btn { width: 100%; }

/* Layout */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--bg-2); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; }
.top-right { display: flex; align-items: center; gap: 10px; }
.ws-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.ws-dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.ws-dot.off { background: var(--err); }

.grid {
  flex: 1; display: grid; grid-template-columns: 230px 320px 1fr;
  min-height: 0;
}
.col { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--bg-2); }
.col-chat { background: var(--bg); }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.col-head h2 { font-size: 14px; margin: 0; }
.search { margin: 8px 12px; width: auto; }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li {
  padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 3px;
}
.list li:hover { background: var(--bg-3); }
.list li.active { background: var(--me); }
.item-title { font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.item-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #06223a; border-radius: 10px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.status-dot.on { background: var(--ok); }
.status-dot.off { background: var(--muted); }
.acc-actions { margin-top: 4px; }
.acc-actions button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 11px; padding: 0; }
.acc-actions button:hover { color: var(--err); }

.empty { padding: 24px 16px; color: var(--muted); text-align: center; }

/* Chat */
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg-2); }
.chat-title { font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble {
  max-width: 70%; padding: 8px 12px; border-radius: 12px; line-height: 1.35;
  word-wrap: break-word; white-space: pre-wrap;
}
.bubble.them { background: var(--them); align-self: flex-start; border-bottom-left-radius: 3px; }
.bubble.me { background: var(--me); align-self: flex-end; border-bottom-right-radius: 3px; }
.bubble .time { display: block; font-size: 10px; color: var(--muted); margin-top: 3px; text-align: right; }
.media { margin-top: 6px; }
.file-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.07); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 7px 10px; cursor: pointer; font-size: 13px;
}
.file-btn:hover { background: rgba(255,255,255,.14); }
.file-btn span { font-weight: 600; }
.file-btn:disabled { opacity: .6; cursor: default; }

.btn-grid { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.btn-row { display: flex; gap: 5px; }
.tg-btn {
  flex: 1; padding: 7px 10px; border-radius: 8px; cursor: pointer;
  background: rgba(46,166,255,.15); border: 1px solid var(--accent);
  color: var(--accent); font-size: 13px; font-weight: 600;
}
.tg-btn:hover { background: rgba(46,166,255,.28); }
.tg-btn:disabled { opacity: .5; cursor: default; }

.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg-2); }
.composer input { margin: 0; }
.composer .btn { white-space: nowrap; }

/* Modais */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 380px; }
.modal-card h3 { margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Toasts */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { padding: 12px 16px; border-radius: 10px; background: var(--bg-3); border: 1px solid var(--border); max-width: 320px; animation: slidein .2s; }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--err); }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
