* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Verdana, sans-serif;
  font-size: 13px;
  background: #6a8bbf url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="4" height="4"><rect width="4" height="4" fill="%236a8bbf"/></svg>');
  min-height: 100vh;
  color: #222;
}

.screen {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 12px;
}

/* ---- Window chrome shared by sign-in / main / chat windows ---- */
.msn-window, .signin-window {
  background: #ece9f7;
  border: 1px solid #4a6ea9;
  border-radius: 8px 8px 4px 4px;
  box-shadow: 3px 3px 12px rgba(0,0,0,0.35);
  overflow: hidden;
}

.titlebar {
  background: linear-gradient(to bottom, #6fa8ea 0%, #3f7fd6 45%, #2c63b8 55%, #1a4f9e 100%);
  color: #fff;
  padding: 6px 8px;
  font-weight: bold;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-shadow: 0 1px 1px rgba(0,0,0,0.4);
  cursor: default;
}

.title-controls button {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  width: 20px;
  height: 18px;
  font-size: 11px;
  line-height: 1;
  border-radius: 3px;
  cursor: pointer;
  margin-left: 4px;
}
.title-controls button:hover { background: #e0504a; }

/* ---- Sign in screen ---- */
.signin-window { width: 340px; }
.signin-body { padding: 20px 24px 24px; background: #fff; }
.signin-logo { text-align: center; margin-bottom: 18px; }
.signin-logo .butterfly { font-size: 34px; }
.signin-logo h1 {
  font-size: 22px;
  margin: 4px 0 0;
  color: #1a4f9e;
  font-weight: 800;
}
.signin-logo .messenger-word { color: #ff7f27; margin-left: 4px; }

#login-form label, #register-form label {
  display: block;
  margin: 10px 0 4px;
  font-weight: 600;
  color: #333;
}
#login-form input, #register-form input {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #8ba7cf;
  border-radius: 3px;
  font-size: 13px;
}
.btn-primary {
  margin-top: 16px;
  width: 100%;
  padding: 9px;
  background: linear-gradient(to bottom, #4f9cf0, #1a63c4);
  border: 1px solid #12488f;
  color: #fff;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.btn-primary:hover { background: linear-gradient(to bottom, #61aafc, #2874db); }
.switch-link { text-align: center; margin-top: 12px; font-size: 12px; }
.switch-link a { color: #1a4f9e; }
.error { color: #c0392b; font-size: 12px; min-height: 14px; margin: 6px 0 0; }

/* ---- Main contact list window ---- */
.main-window { width: 300px; background: #f4f6fb; }
.my-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 4px;
}
.avatar-blob {
  width: 40px; height: 40px;
  background: #fff;
  border: 2px solid #8ba7cf;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.my-info { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.name-input {
  border: none; background: transparent;
  font-weight: bold; font-size: 14px; color: #1a4f9e;
  padding: 2px;
}
.name-input:focus { outline: 1px solid #8ba7cf; background: #fff; }
#my-status-select {
  font-size: 12px; border: 1px solid #cdd7e8; border-radius: 3px; padding: 2px;
}
.status-message-input {
  width: calc(100% - 20px);
  margin: 4px 10px 8px;
  padding: 5px 7px;
  font-size: 12px;
  font-style: italic;
  border: 1px solid #cdd7e8;
  border-radius: 3px;
  color: #555;
}

.contacts-area { max-height: 480px; overflow-y: auto; padding-bottom: 8px; }
.group-header {
  font-size: 11px;
  font-weight: bold;
  color: #1a4f9e;
  padding: 6px 10px 3px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.contact-list { list-style: none; margin: 0; padding: 0 6px; }
.contact-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.contact-item:hover { background: #dbe6fb; }
.contact-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot-online { background: #57c33b; box-shadow: 0 0 3px #57c33b; }
.dot-away { background: #f0b429; }
.dot-busy { background: #d5453a; }
.dot-offline { background: #b7b7b7; }
.contact-text { display: flex; flex-direction: column; overflow: hidden; }
.contact-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-name.offline-name { color: #8a8a8a; }
.contact-msg { font-size: 11px; color: #6b7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-msg { padding: 20px; text-align: center; color: #888; font-size: 12px; }

/* ---- Chat windows ---- */
#chat-windows {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
.chat-window {
  position: absolute;
  width: 380px;
  pointer-events: all;
  background: #f4f6fb;
}
.chat-body { display: flex; flex-direction: column; height: 420px; }
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  background: #fff;
  border-bottom: 1px solid #cdd7e8;
}
.msg-row { margin-bottom: 10px; max-width: 90%; }
.msg-row.mine { margin-left: auto; text-align: right; }
.msg-sender { font-size: 11px; font-weight: bold; color: #1a4f9e; margin-bottom: 2px; }
.msg-row.mine .msg-sender { color: #b5511f; }
.msg-bubble {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 8px;
  background: #eef2fb;
  font-size: 13px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
  text-align: left;
}
.msg-row.mine .msg-bubble { background: #dff0d8; }
.msg-time { font-size: 10px; color: #999; margin-top: 2px; }
.msg-bubble img { max-width: 220px; border-radius: 4px; display: block; margin-top: 4px; }
.msg-nudge { font-style: italic; color: #b5511f; font-size: 12px; text-align: center; margin: 6px 0; }

.typing-indicator { font-size: 11px; color: #888; padding: 2px 10px; font-style: italic; min-height: 14px; }

.chat-toolbar {
  display: flex;
  gap: 6px;
  padding: 5px 8px;
  border-bottom: 1px solid #cdd7e8;
  background: #e6ecf7;
}
.chat-toolbar button, .image-btn {
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid #b9c7e2;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
}
.chat-toolbar button:hover, .image-btn:hover { background: #dbe6fb; }

.emoji-picker {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 6px;
  background: #fff;
  border-bottom: 1px solid #cdd7e8;
}
.emoji-picker span { cursor: pointer; font-size: 18px; text-align: center; padding: 2px; border-radius: 3px; }
.emoji-picker span:hover { background: #dbe6fb; }

.chat-input-row {
  display: flex;
  gap: 6px;
  padding: 8px;
}
.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid #b9c7e2;
  border-radius: 3px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
}
.send-btn {
  padding: 0 16px;
  background: linear-gradient(to bottom, #4f9cf0, #1a63c4);
  border: 1px solid #12488f;
  color: #fff;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
}
.send-btn:hover { background: linear-gradient(to bottom, #61aafc, #2874db); }

/* Nudge shake animation */
@keyframes nudge-shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-8px, -4px); }
  20% { transform: translate(8px, 4px); }
  30% { transform: translate(-8px, 4px); }
  40% { transform: translate(8px, -4px); }
  50% { transform: translate(-6px, 0); }
  60% { transform: translate(6px, 2px); }
  70% { transform: translate(-4px, -2px); }
  80% { transform: translate(4px, 0); }
  90% { transform: translate(-2px, 0); }
}
.chat-window.shaking { animation: nudge-shake 0.6s; }

.groups-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 6px;
}
.mini-btn {
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid #8ba7cf;
  border-radius: 10px;
  background: #fff;
  color: #1a4f9e;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: bold;
}
.mini-btn:hover { background: #dbe6fb; }
.group-icon { font-size: 15px; }

/* ---- New group modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  width: 320px;
  background: #f4f6fb;
  border: 1px solid #4a6ea9;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 3px 3px 16px rgba(0,0,0,0.4);
}
.modal-body { padding: 14px 16px 16px; }
.modal-body label {
  display: block;
  font-weight: 600;
  margin: 10px 0 4px;
  color: #333;
  font-size: 12px;
}
.modal-body input[type="text"] {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #8ba7cf;
  border-radius: 3px;
  font-size: 13px;
}
.member-checklist {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid #cdd7e8;
  border-radius: 4px;
  padding: 4px;
  background: #fff;
}
.member-check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px;
  font-size: 13px;
}
.member-check-row label { display: inline; margin: 0; font-weight: normal; }
.modal-body .btn-primary { margin-top: 14px; }
.no-members-msg { padding: 8px; color: #888; font-size: 12px; text-align: center; }

@media (max-width: 480px) {
  .chat-window { width: 92vw; left: 4vw !important; }
  .main-window, .signin-window { width: 92vw; }
}
