:root {
  --bg-primary: #17212b;
  --bg-secondary: #1f2c38;
  --bg-chat: #0b141f;
  --border: #2b3a47;
  --accent: #2b5278;
  --accent-hover: #3a6a99;
  --text: #ffffff;
  --text-muted: #aaaaaa;
  --text-url: #8888f7;
  --scroll-track: #1a2a3a;
  --scroll-thumb: #4a5f73;
  --scroll-thumb-hover: #5f7a94;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
}

a {
  color: var(--text-url);
  text-decoration: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
}

.app {
  width: 100%;
  height: 100vh;
  display: flex;
  overflow: hidden;
  position: relative;
  background: var(--bg-primary);
}

.sidebar {
  width: 320px;
  border-right: 1px solid var(--bg-secondary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: var(--bg-primary);
}

.sidebar-header {
  padding: 18px 16px 12px;
  font-size: 24px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.contact-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--bg-secondary);
  cursor: pointer;
  background: var(--bg-primary);
}

.contact-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  font-size: 18px;
  flex-shrink: 0;
  text-transform: uppercase;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.contact-info h4 {
  font-size: 17px;
  font-weight: 500;
  line-height: 1.3;
}

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  min-width: 0;
}

.chat-header {
  padding: 11px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 85%;
}

.bubble {
  background: var(--bg-secondary);
  padding: 10px 14px;
  border-radius: 18px 18px 18px 4px;
  word-break: break-word;
}

.bubble .name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.bubble .text {
  font-size: 16px;
  line-height: 1.4;
}

.chat-footer {
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.svg-small {
  width: 20px;
  height: 20px;
  fill: white;
}

.view-content {
  max-width: 480px;
  border-radius: 12px;
  overflow: hidden;
  margin: 4px 0 2px;
}

.view-content img, .view-content video {
  width: 100%;
  height: auto;
  display: block;
}

.message-input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 16px;
  outline: none;
  resize: none;
  min-height: 40px;
  max-height: 200px;
  line-height: 1.5;
  font-family: inherit;
  overflow-y: auto;
}

.message-input::-webkit-scrollbar {
  width: 4px;
}

.message-input::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-radius: 2px;
}

.message-input::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 2px;
}

.message-input:focus {
  border-color: var(--accent);
}

.message-input:focus {
  border-color: var(--accent);
}

.send-btn {
  background: var(--accent);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: 0.2s;
}

.send-btn:hover {
  background: var(--accent);
}

.avatar-small {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  font-size: 15px;
  flex-shrink: 0;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.profile-icon {
  display: flex;
  font-size: 18px;
  cursor: pointer;
  margin-left: auto;
}

.profile-menu {
  position: absolute;
  top: 70px;
  right: 20px;
  background: var(--bg-secondary);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  display: none;
  width: 200px;
  z-index: 1000;
  border: 1px solid var(--border);
  font-weight: 600;
}

.menu-header {
  padding: 16px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-title {
  cursor: pointer;
}

.menu-items {
  padding: 8px 0;
  font-weight: 400;
}

.menu-item {
  padding: 12px 16px;
  cursor: pointer;
  transition: 0.2s;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.show {
  display: block;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

.menu-username {
  cursor: pointer;
}

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal {
  background: var(--bg-secondary);
  border-radius: 16px;
  width: 90%;
  max-width: 380px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  border: 1px solid var(--border);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 18px;
}

.modal-close {
  font-size: 22px;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.modal-close:hover {
  opacity: 1;
}

.modal-body {
  padding: 20px;
}

.modal-input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 12px;
  font-size: 15px;
  outline: none;
}

.modal-input:focus {
  border-color: var(--accent);
}

.modal-file {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-file-label {
  background: var(--accent);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.modal-file-label:hover {
  background: var(--accent);
}

.modal-file-name {
  font-size: 14px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-footer {
  padding: 16px 20px 20px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-btn {
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: 0.2s;
}

.modal-btn-cancel {
  background: transparent;
  border: 1px solid var(--border);
}

.modal-btn-cancel:hover {
  background: var(--border);
}

.modal-btn-create {
  background: var(--accent);
}

.modal-btn-create:hover {
  background: var(--accent);
}

textarea.modal-input {
  resize: vertical;
}

.contact-avatar[style*="background-image"],
.avatar-small[style*="background-image"] {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.contact-item.selected {
  background: var(--accent);
  opacity: 0.9;
}

.attach-btn {
  background: transparent;
  border: none;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.attach-btn svg {
  fill: var(--text-muted);
}

.attach-btn:hover svg {
  fill: var(--text);
}

.view-content img,
.view-content video {
  max-height: 70vh;
  border-radius: 8px;
}

.view-content audio {
  width: 300px;
}

@media (max-width: 730px) {
  .sidebar {
    display: none;
  }

  .avatar-small {
    width: 38px;
    height: 38px;
  }
}