* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #14151a;
  color: #e7e7ea;
}
input, select, button {
  font-family: inherit;
  font-size: 16px;
}
input, select {
  display: block;
  width: 100%;
  padding: 10px;
  margin-bottom: 8px;
  background: #1e2027;
  border: 1px solid #333644;
  border-radius: 6px;
  color: #e7e7ea;
}
button {
  padding: 10px 14px;
  border: none;
  border-radius: 6px;
  background: #4b6fff;
  color: white;
  cursor: pointer;
}
button.secondary { background: #333644; }
button.danger { background: #b6362c; }
button.small { padding: 6px 10px; font-size: 13px; }
button:hover { filter: brightness(1.1); }
.menu-toggle { display: none; }

.view { min-height: 100vh; }
#auth-view { display: flex; align-items: center; justify-content: center; }
.card {
  background: #1c1e26;
  padding: 24px;
  border-radius: 10px;
  width: 320px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}
.card h1, .card h3 { margin-top: 0; }
.hint { color: #8a8d99; font-size: 12px; }
.error { color: #ff6b6b; font-size: 13px; margin-top: 6px; min-height: 16px; }
.row { display: flex; gap: 8px; }
.row button { flex: 1; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #1c1e26;
  border-bottom: 1px solid #2a2c36;
}
#whoami { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#sidebar-backdrop { display: none; }

.layout { display: flex; height: calc(100vh - 49px); }
aside {
  width: 280px;
  background: #191a20;
  border-right: 1px solid #2a2c36;
  padding: 12px;
  overflow-y: auto;
}
aside section { margin-bottom: 24px; }
aside h3 { font-size: 13px; text-transform: uppercase; color: #8a8d99; margin: 0 0 8px; }

.code-display {
  font-family: monospace;
  background: #0f1015;
  padding: 8px;
  border-radius: 6px;
  text-align: center;
  margin-bottom: 8px;
  min-height: 16px;
  word-break: break-all;
}

.friend-row, .request-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  border-radius: 6px;
  margin-bottom: 4px;
  background: #1e2027;
}
.friend-row:hover { background: #262936; cursor: pointer; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; display: inline-block; margin-right: 6px; }
.dot.online { background: #3ecf5e; }

main { flex: 1; display: flex; flex-direction: column; }
.empty { margin: auto; color: #565968; }

#chat-window { display: flex; flex-direction: column; height: 100%; }
.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid #2a2c36;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.chat-header #chat-with { font-weight: 600; }
.chat-header #chat-status { flex: 1; }
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg { max-width: 60%; padding: 8px 12px; border-radius: 10px; background: #262936; word-wrap: break-word; white-space: pre-wrap; }
.msg.mine { align-self: flex-end; background: #3b4ba8; }
.msg.locked { opacity: 0.5; font-style: italic; }
.msg .sender { display: block; font-size: 11px; color: #9a9dab; margin-bottom: 2px; }

.checkbox-list { max-height: 160px; overflow-y: auto; margin-bottom: 8px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.checkbox-row input { width: auto; margin: 0; }

#send-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid #2a2c36; }
#send-form input { margin-bottom: 0; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}

/* ---------- mobile ---------- */
@media (max-width: 800px) {
  .menu-toggle { display: inline-block; }

  .layout { position: relative; height: calc(100vh - 57px); }

  aside {
    position: fixed;
    top: 57px;
    bottom: 0;
    left: 0;
    width: 85vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 20;
  }
  aside.open { transform: translateX(0); }

  #sidebar-backdrop {
    display: block;
    position: fixed;
    top: 57px;
    inset: 57px 0 0 0;
    background: rgba(0,0,0,0.5);
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  #sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

  main { width: 100%; }
  .msg { max-width: 82%; }
  #btn-panic { font-size: 12px; padding: 8px 10px; }
  .chat-header #chat-with { font-size: 15px; }
}

