/* Basic reset */
* {
  box-sizing: border-box;
}

:root {
  --bg-main: #e7edf3;
  --panel: #ffffff;
  --panel-soft: #f6f8fb;
  --line: #d6dee8;
  --text-main: #17212b;
  --text-soft: #5f6c7b;
  --brand: #0f766e;
  --brand-strong: #0b5f58;
  --self-bubble: #d7f5de;
  --other-bubble: #ffffff;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top left, #f6fbff, var(--bg-main));
  color: var(--text-main);
}

/* Main app wrapper */
.app {
  max-width: 860px;
  margin: 20px auto;
  background: var(--panel);
  border-radius: 16px;
  border: 1px solid rgba(15, 118, 110, 0.08);
  box-shadow: 0 18px 50px rgba(20, 30, 50, 0.15);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 40px);
}

/* Header */
.chat-header {
  padding: 18px 20px;
  background: linear-gradient(135deg, #0f766e, #0b5f58);
  color: #f8fffe;
}

.chat-header h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.2px;
}

.chat-header p {
  margin: 6px 0 0;
  font-size: 0.92rem;
  opacity: 0.96;
}

/* Auth rows */
.auth-section {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto auto;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.auth-section input,
.auth-section button {
  min-height: 40px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid #bcc9d9;
  font-size: 0.95rem;
}

.auth-section input:focus,
.auth-section button:focus,
.username-section input:focus,
.composer input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.25);
  outline-offset: 1px;
  border-color: rgba(15, 118, 110, 0.55);
}

#signUpButton,
#loginButton,
#logoutButton {
  font-weight: 600;
  cursor: pointer;
}

#signUpButton {
  background: #ffffff;
}

#loginButton {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
}

#loginButton:hover {
  background: var(--brand-strong);
}

#logoutButton {
  background: #fff7f7;
  color: #a61b1b;
  border-color: #efc9c9;
}

.status-section {
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
  font-size: 0.9rem;
  color: var(--text-soft);
}

/* Username row */
.username-section {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.username-section label {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
}

.username-section input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #bcc9d9;
  border-radius: 10px;
}

/* Chat list area */
.chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background:
    linear-gradient(rgba(248, 252, 255, 0.88), rgba(248, 252, 255, 0.88)),
    repeating-linear-gradient(
      45deg,
      rgba(155, 175, 200, 0.08),
      rgba(155, 175, 200, 0.08) 10px,
      rgba(155, 175, 200, 0.04) 10px,
      rgba(155, 175, 200, 0.04) 20px
    );
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-box:empty::before {
  content: "No messages yet. Log in and send your first note to yourself.";
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.8);
  border: 1px dashed #c5d1df;
  border-radius: 12px;
  padding: 12px 14px;
  max-width: 420px;
}

/* Message bubble base */
.message {
  max-width: 78%;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid rgba(20, 40, 70, 0.08);
  line-height: 1.4;
  word-wrap: break-word;
  box-shadow: 0 3px 8px rgba(20, 30, 40, 0.08);
}

/* Current user's messages (right side) */
.message.self {
  align-self: flex-end;
  background: var(--self-bubble);
}

/* Other users' messages (left side) */
.message.other {
  align-self: flex-start;
  background: var(--other-bubble);
}

.message .meta {
  font-size: 0.77rem;
  color: #5d6b79;
  margin-bottom: 5px;
}

.message .text {
  font-size: 0.98rem;
}

/* Composer at bottom */
.composer {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel-soft);
}

.composer input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #bcc9d9;
  border-radius: 10px;
  font-size: 0.95rem;
}

.composer button {
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: white;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
}

.composer button:hover {
  background: var(--brand-strong);
}

button:disabled,
input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Small screen adjustments */
@media (max-width: 768px) {
  .auth-section {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  #signUpButton,
  #loginButton,
  #logoutButton {
    grid-column: span 1;
  }

  .app {
    margin: 0;
    border-radius: 0;
    height: 100vh;
  }

  .message {
    max-width: 88%;
  }
}
