:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e2230;
  --border: #2a2f40;
  --text: #e6e8ef;
  --muted: #8b91a7;
  --accent: #6c8cff;
  --accent-2: #4f6ef7;
  --mine: #2b3a67;
  --theirs: #232735;
  --danger: #ff6b6b;
  --ok: #4ade80;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
button { cursor: pointer; font: inherit; }
input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.primary {
  background: var(--accent-2);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 600;
}
.primary:hover { background: var(--accent); }
.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
}
.ghost:hover { color: var(--text); border-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 14px; margin: 4px 0; }

/* Auth */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
}
.auth-card h1 { margin: 0 0 6px; font-size: 26px; }
.tagline { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  flex: 1;
  padding: 8px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.tab.active { color: #fff; background: var(--accent-2); border-color: transparent; }
#auth-form label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
#auth-form input { margin-top: 6px; }
#auth-submit { width: 100%; margin-top: 6px; }

/* App layout */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-head {
  padding: 18px 16px 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.sidebar-id { min-width: 0; }
.logo { font-weight: 700; font-size: 18px; display: block; }
.my-handle { color: var(--accent); font-size: 14px; }
.lang-toggle { white-space: nowrap; font-size: 13px; }
.lang-row { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.sidebar-actions { display: flex; gap: 8px; padding: 10px 16px; }
.sidebar-label {
  padding: 12px 16px 6px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}
.user-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.user-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
}
.user-list li:hover { background: var(--panel-2); }
.user-list li.active { background: var(--accent-2); color: #fff; }
.user-list .badge {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
}
.user-list li.active .badge { background: #fff; color: var(--accent-2); }

/* Chat */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
}
.thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.thread-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  gap: 12px;
  align-items: baseline;
}
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 72%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.msg.theirs { background: var(--theirs); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.mine { background: var(--mine); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 6px; }
.msg.mine .meta { color: #a8b6e8; }
.composer {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.composer textarea { resize: none; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; }
.key-create { display: flex; gap: 10px; margin: 16px 0; }
.new-key {
  background: var(--panel-2);
  border: 1px solid var(--ok);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}
.new-key code { display: block; word-break: break-all; margin: 8px 0; color: var(--ok); font-size: 13px; }
.key-list { list-style: none; margin: 0; padding: 0; }
.key-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.key-list .revoked { color: var(--muted); text-decoration: line-through; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  z-index: 20;
}

@media (max-width: 640px) {
  .sidebar { width: 180px; min-width: 180px; }
  .msg { max-width: 90%; }
}