:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #183b36;
  background: #eef5f2;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
}

.app-header {
  background: #075e54;
  color: white;
  padding: 22px max(20px, calc((100vw - 1160px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  font-size: 36px;
}

h1 {
  margin: 0;
  font-size: clamp(20px, 4vw, 28px);
}

.brand p {
  margin: 5px 0 0;
  color: #d0eee3;
}

main {
  max-width: 1160px;
  margin: 24px auto;
  padding: 0 20px;
}

#notice {
  padding: 14px 18px;
  background: #e0f1e9;
  border: 1px solid #badccd;
  border-radius: 12px;
  overflow-wrap: anywhere;
}

#notice.error {
  background: #fff0ee;
  border-color: #e8b4ac;
  color: #8a2419;
}

.card {
  max-width: 460px;
  margin: 32px auto;
  padding: 30px;
  background: white;
  border: 1px solid #dce7e1;
  border-radius: 20px;
  box-shadow: 0 12px 36px #183b3610;
}

h2 {
  margin-top: 0;
  font-size: 23px;
}

p {
  line-height: 1.6;
}

form {
  display: grid;
  gap: 12px;
}

label {
  font-weight: 600;
  margin-top: 6px;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid #bdcec5;
  border-radius: 10px;
  background: white;
  color: #183b36;
}

textarea {
  resize: vertical;
}

button {
  padding: 12px 16px;
  border: 0;
  border-radius: 10px;
  background: #087f68;
  color: white;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: #075e54;
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

:focus-visible {
  outline: 3px solid #d6a526;
  outline-offset: 3px;
}

#signup-button,
#refresh-chats {
  background: #e5f2ec;
  color: #075e54;
}

#logout-button {
  background: white;
  color: #075e54;
}

#username-help {
  margin: 0;
  font-size: 14px;
  color: #526b60;
}

#messenger-section {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  min-height: 580px;
  background: white;
  border: 1px solid #dce7e1;
  border-radius: 18px;
  overflow: hidden;
}

.chat-sidebar {
  padding: 24px;
  border-right: 1px solid #dce7e1;
}

#my-profile {
  color: #526b60;
  overflow-wrap: anywhere;
}

#refresh-chats {
  width: 100%;
  margin: 20px 0 12px;
}

#chat-list,
#search-results {
  display: grid;
  gap: 10px;
}

#search-results {
  margin-top: 14px;
}

.chat-item {
  width: 100%;
  text-align: left;
  background: #eef5f2;
  color: #183b36;
  overflow-wrap: anywhere;
}

.chat-item:hover,
.chat-item.active {
  background: #ccebdd;
  color: #075e54;
}

.conversation {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #f5f8f4;
}

#chat-title {
  padding: 20px 24px;
  margin: 0;
  background: #e5f2ec;
  overflow-wrap: anywhere;
}

#messages {
  flex: 1;
  height: 400px;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 85%;
  align-self: flex-start;
  padding: 12px 16px;
  border-radius: 14px 14px 14px 3px;
  background: white;
  border: 1px solid #dce7e1;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.own {
  align-self: flex-end;
  background: #d9f5df;
  border-radius: 14px 14px 3px 14px;
}

.message time {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: #526b60;
}

#message-form {
  padding: 18px;
  background: white;
  border-top: 1px solid #dce7e1;
}

footer {
  text-align: center;
  padding: 16px;
  color: #526b60;
  font-size: 14px;
}

@media (max-width: 720px) {
  .app-header {
    padding: 18px;
    flex-wrap: wrap;
  }

  main {
    padding: 0 12px;
    margin-top: 16px;
  }

  .card {
    padding: 24px;
  }

  #messenger-section {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    border-right: 0;
    border-bottom: 1px solid #dce7e1;
  }

  #chat-list {
    max-height: 220px;
    overflow-y: auto;
  }

  #messages {
    flex: none;
    height: 380px;
    padding: 16px;
  }
}
