* { box-sizing: border-box; }
:root {
  font-family: Tahoma, Verdana, Arial, sans-serif;
  color: #17233a;
  background: #dbeafa;
}
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.95), transparent 28%),
    linear-gradient(160deg, #eaf5ff 0%, #bedcf6 50%, #8dbbe4 100%);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-window, .contact-window, .chat-window, .modal {
  border: 1px solid #7297bb;
  box-shadow: 0 12px 40px rgba(31,72,110,.25), inset 0 1px #fff;
  background: #f7fbff;
}
.login-window {
  width: min(390px, 95vw);
  border-radius: 10px;
  overflow: hidden;
}
.brand-area {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 24px;
  background: linear-gradient(#eaf8ff, #b9dcf7);
  border-bottom: 1px solid #8bb4d7;
}
.brand-orb {
  width: 58px;
  height: 58px;
  border-radius: 50% 50% 45% 55%;
  display: grid;
  place-items: center;
  color: white;
  font: bold 30px Arial;
  background: linear-gradient(145deg, #5fcb4a, #2e95e9 55%, #f3a12e);
  box-shadow: inset 0 2px 4px rgba(255,255,255,.8), 0 2px 5px rgba(0,0,0,.2);
}
.brand-title { font-size: 30px; font-weight: 700; color: #1d5f99; line-height: 1; }
.brand-subtitle { color: #68849d; letter-spacing: 3px; margin-top: 4px; }

.auth-tabs { display: flex; border-bottom: 1px solid #b5cadd; }
.tab {
  flex: 1;
  padding: 11px;
  border: 0;
  background: #edf5fc;
  color: #44627d;
}
.tab.active { background: white; color: #164f82; font-weight: 700; }
.auth-form { display: grid; gap: 8px; padding: 20px 24px 8px; }
.auth-form label, .profile-form label { font-size: 12px; color: #526c83; margin-top: 4px; }
input, select {
  border: 1px solid #9ab3c8;
  border-radius: 4px;
  background: white;
  padding: 9px 10px;
  outline: none;
}
input:focus, select:focus { border-color: #3a91d4; box-shadow: 0 0 0 2px rgba(58,145,212,.15); }
.primary-btn {
  margin-top: 10px;
  border: 1px solid #427db1;
  border-radius: 5px;
  padding: 9px 14px;
  color: white;
  font-weight: 700;
  background: linear-gradient(#65aee3, #2f7dbc);
  box-shadow: inset 0 1px rgba(255,255,255,.5);
}
.error-text { color: #a62a2a; min-height: 20px; padding: 4px 24px 8px; font-size: 12px; }
.login-footer { padding: 12px 24px 18px; font-size: 11px; text-align: center; color: #7a92a8; }

.app-screen { min-height: 100vh; padding: 36px; }
.contact-window {
  width: min(390px, calc(100vw - 28px));
  height: min(680px, calc(100vh - 72px));
  margin: 0 auto;
  border-radius: 9px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.contact-header {
  min-height: 118px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 17px 14px;
  background:
    radial-gradient(circle at 90% 0, rgba(255,255,255,.8), transparent 35%),
    linear-gradient(#dff3ff, #9ed0f2);
  border-bottom: 1px solid #78a9cf;
}
.avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: white;
  font-weight: 700;
  background: linear-gradient(145deg, #79bd52, #4b91d1);
  border: 3px solid white;
  outline: 1px solid #77a2c6;
  text-transform: uppercase;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.big { width: 70px; height: 70px; font-size: 22px; }
.me-info { min-width: 0; flex: 1; }
.name-line { display: flex; flex-direction: column; gap: 5px; }
.name-line strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; }
.status-select { padding: 3px 4px; width: 120px; font-size: 11px; background: rgba(255,255,255,.75); }
.personal-message {
  max-width: 230px;
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #526d83;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  align-self: flex-start;
  width: 30px;
  height: 30px;
  border: 1px solid #7aa3c4;
  border-radius: 5px;
  background: rgba(255,255,255,.55);
  color: #285a83;
}
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  padding: 9px;
  border-bottom: 1px solid #c8d9e6;
  background: linear-gradient(#fdfefe, #e9f2f9);
}
.toolbar input { min-width: 0; padding: 7px 8px; }
.toolbar-btn {
  border: 1px solid #9cb6cb;
  border-radius: 4px;
  background: linear-gradient(#fff, #dceaf5);
  color: #355b78;
  padding: 5px 8px;
  font-size: 11px;
}
.count-badge {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  padding: 0 4px;
  color: white;
  background: #e04b39;
  font-size: 10px;
}
.contacts { flex: 1; min-height: 0; background: white; overflow: auto; }
.group-title {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  padding: 7px 10px;
  color: #315d7e;
  font-weight: 700;
  font-size: 12px;
  background: linear-gradient(#eef7fd, #d9ebf7);
  border-bottom: 1px solid #c3dae9;
}
.friend-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-bottom: 1px solid #eef3f7;
  cursor: pointer;
}
.friend-row:hover { background: #eef7ff; }
.friend-meta { min-width: 0; flex: 1; }
.friend-name { font-size: 13px; color: #1e3f59; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend-message { margin-top: 2px; color: #7a8f9e; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.presence-dot {
  width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15);
}
.presence-online { background: #4fbe44; }
.presence-busy { background: #e34a42; }
.presence-away { background: #eab23c; }
.presence-offline { background: #b5bec5; }
.unread-badge { min-width: 21px; padding: 2px 6px; border-radius: 10px; background: #e85d40; color: white; font-size: 10px; text-align: center; }
.empty-state { padding: 35px 20px; text-align: center; color: #7c91a3; font-size: 12px; }
.contact-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  border-top: 1px solid #b9cfdf;
  background: linear-gradient(#edf6fc, #d7e9f5);
  color: #678297;
  font-size: 10px;
}
.link-btn { border: 0; background: transparent; color: #2e6f9f; font-size: 10px; }

.chat-layer { position: fixed; inset: 0; pointer-events: none; }
.chat-window {
  position: absolute;
  width: min(620px, calc(100vw - 24px));
  height: min(560px, calc(100vh - 24px));
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  border-radius: 9px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.chat-titlebar {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 70px;
  padding: 10px 12px;
  background: linear-gradient(#dff4ff, #91c8ee);
  border-bottom: 1px solid #6c9fc4;
}
.chat-title { min-width: 0; flex: 1; }
.chat-title strong { display: block; color: #1d4e73; }
.chat-title span { display: block; margin-top: 3px; font-size: 11px; color: #607e94; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.window-btn {
  width: 28px; height: 25px; border: 1px solid #789fbd; border-radius: 4px;
  background: linear-gradient(#fff, #dcebf6); color: #305b7a;
}
.chat-actions { display: flex; gap: 5px; padding: 6px 8px; background: #edf5fa; border-bottom: 1px solid #ccdce7; }
.action-btn { border: 1px solid #a4bacb; border-radius: 4px; background: linear-gradient(#fff,#e3edf4); padding: 5px 9px; color: #3f6078; font-size: 11px; }
.chat-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 118px; background: white; }
.messages { overflow-y: auto; padding: 12px; }
.side-avatar { border-left: 1px solid #d8e3eb; padding: 16px; background: #f7fbfe; display: flex; justify-content: center; align-items: flex-start; }
.side-avatar .avatar { width: 86px; height: 86px; font-size: 28px; }
.message { margin-bottom: 10px; font-size: 13px; line-height: 1.35; }
.message-head { font-size: 11px; color: #57758a; margin-bottom: 2px; }
.message.me .message-head { color: #2b6d9f; font-weight: 700; }
.message-text { white-space: pre-wrap; word-break: break-word; color: #25384a; }
.typing { height: 20px; padding: 2px 10px; color: #718b9e; font-size: 10px; background: white; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 7px; padding: 8px; border-top: 1px solid #c8d9e5; background: #edf5fa; }
.composer textarea { resize: none; min-height: 66px; max-height: 100px; border: 1px solid #9fb6c8; border-radius: 4px; padding: 7px; font: 13px Tahoma; }
.send-btn { min-width: 80px; border: 1px solid #4b83ae; border-radius: 4px; color: #17466a; font-weight: 700; background: linear-gradient(#fff,#cfe6f7); }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(34,62,85,.28); padding: 16px; }
.modal { width: min(440px, 96vw); max-height: 80vh; border-radius: 8px; overflow: hidden; }
.modal-title { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; font-weight: 700; color: #285776; background: linear-gradient(#e6f6ff,#a8d4f1); border-bottom: 1px solid #82acd0; }
.close-btn { border: 0; background: transparent; font-size: 24px; line-height: 1; color: #4c6d82; }
.requests-list { max-height: 55vh; overflow: auto; padding: 8px; background: white; }
.request-row { display: flex; align-items: center; gap: 9px; padding: 9px; border-bottom: 1px solid #edf1f5; }
.request-actions { margin-left: auto; display: flex; gap: 5px; }
.profile-form { display: grid; gap: 7px; padding: 15px; background: white; }
.toast-layer { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: grid; gap: 8px; }
.toast { width: min(310px, calc(100vw - 36px)); padding: 11px 12px; border: 1px solid #7ea7c6; border-radius: 7px; color: #264c68; background: linear-gradient(#f9fdff,#dceef9); box-shadow: 0 6px 20px rgba(0,0,0,.18); font-size: 12px; animation: toastIn .2s ease-out; }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } }
@keyframes wizzShake {
  0%,100% { transform: translate(-50%,-50%); }
  10% { transform: translate(calc(-50% - 12px), calc(-50% + 3px)); }
  20% { transform: translate(calc(-50% + 14px), calc(-50% - 4px)); }
  30% { transform: translate(calc(-50% - 15px), calc(-50% - 2px)); }
  40% { transform: translate(calc(-50% + 13px), calc(-50% + 4px)); }
  50% { transform: translate(calc(-50% - 12px), calc(-50% - 4px)); }
  60% { transform: translate(calc(-50% + 10px), calc(-50% + 2px)); }
  70% { transform: translate(calc(-50% - 8px), calc(-50% + 3px)); }
  80% { transform: translate(calc(-50% + 6px), calc(-50% - 2px)); }
  90% { transform: translate(calc(-50% - 4px), calc(-50% + 1px)); }
}
.chat-window.wizz { animation: wizzShake .55s linear; }

@media (max-width: 650px) {
  .app-screen { padding: 8px; }
  .contact-window { height: calc(100vh - 16px); }
  .toolbar { grid-template-columns: 1fr auto; }
  #requestsBtn { grid-column: 1 / -1; }
  .chat-body { grid-template-columns: 1fr; }
  .side-avatar { display: none; }
  .chat-window { height: calc(100vh - 16px); width: calc(100vw - 16px); }
}
