/* WhatsApp-like UI */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #ECE5DD;
  color: #111;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  border-left: 1px solid #cfc7bd;
  border-right: 1px solid #cfc7bd;
}

/* ---------- LOGIN ---------- */
.login-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #075E54 0%, #128C7E 100%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 16px;
  padding: 32px 28px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  text-align: center;
}
.login-logo {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: #075E54;
  display: grid; place-items: center;
  font-size: 38px;
  margin: 0 auto 12px;
}
.login-card h1 {
  font-size: 24px; margin: 4px 0 2px; color: #075E54;
}
.login-sub {
  font-size: 14px; color: #5b6b73; margin: 0 0 22px;
}
.login-card form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-card label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 13px; color: #54656f; font-weight: 500;
}
.login-card input {
  border: 1px solid #d6d6d6;
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
}
.login-card input:focus { border-color: #128C7E; box-shadow: 0 0 0 3px rgba(18,140,126,0.15); }
.login-card button[type=submit] {
  margin-top: 6px;
  background: #128C7E; color: #fff;
  border: none; border-radius: 8px;
  padding: 12px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.login-card button[type=submit]:hover { background: #075E54; }
.login-card button[type=submit]:disabled { opacity: 0.6; cursor: not-allowed; }
.login-error {
  background: #fde8e8; color: #b91c1c;
  font-size: 13px; padding: 8px 12px; border-radius: 6px;
  text-align: center;
}

/* ---------- APP ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px 10px 14px;
  background: #075E54;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: max(10px, env(safe-area-inset-top));
}

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #128C7E;
  display: grid; place-items: center;
  font-size: 22px;
}

.who { flex: 1; min-width: 0; }
.name { font-weight: 600; font-size: 16px; line-height: 1.1; }
.status { font-size: 12.5px; opacity: 0.85; line-height: 1.1; margin-top: 2px; }

/* ---------- chat area ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px 8px;
  background-color: #ECE5DD;
  background-image:
    radial-gradient(rgba(0,0,0,0.04) 1px, transparent 1px),
    radial-gradient(rgba(0,0,0,0.03) 1px, transparent 1px);
  background-size: 22px 22px, 30px 30px;
  background-position: 0 0, 11px 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.day-divider {
  display: flex; justify-content: center; margin: 8px 0 14px;
}
.day-divider span {
  background: #E1F2FB;
  color: #5b6b73;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
}

.bubble {
  max-width: 80%;
  padding: 6px 9px 18px;
  border-radius: 8px;
  position: relative;
  font-size: 15px;
  line-height: 1.35;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
  margin-bottom: 2px;
}
.bubble.me {
  align-self: flex-end;
  background: #DCF8C6;
  border-top-right-radius: 0;
}
.bubble.them {
  align-self: flex-start;
  background: #FFFFFF;
  border-top-left-radius: 0;
}
.bubble .time {
  position: absolute;
  bottom: 3px;
  right: 8px;
  font-size: 10.5px;
  color: rgba(0,0,0,0.45);
  user-select: none;
}
.bubble img, .bubble video {
  max-width: 100%;
  border-radius: 6px;
  display: block;
  margin-bottom: 4px;
}
.bubble audio { width: 100%; margin-bottom: 4px; }

.typing {
  align-self: flex-start;
  background: #FFFFFF;
  padding: 10px 14px;
  border-radius: 8px;
  border-top-left-radius: 0;
  display: inline-flex;
  gap: 4px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
}
.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #b6b6b6;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- composer ---------- */
.composer {
  background: #F0F0F0;
  padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  border-top: 1px solid #d9d9d9;
}

.preview {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px 4px;
  border-bottom: 1px solid #e3e3e3;
  margin-bottom: 6px;
}
.preview .item {
  position: relative;
  width: 64px; height: 64px;
  background: #ddd;
  border-radius: 6px;
  overflow: hidden;
  display: grid; place-items: center;
  font-size: 22px;
}
.preview .item img { width: 100%; height: 100%; object-fit: cover; }
.preview .item .x {
  position: absolute; top: 2px; right: 2px;
  background: rgba(0,0,0,0.6); color: #fff;
  width: 18px; height: 18px; border-radius: 50%;
  font-size: 11px; display: grid; place-items: center;
  cursor: pointer;
}

.row { display: flex; align-items: flex-end; gap: 6px; }

textarea#input {
  flex: 1;
  border: none;
  outline: none;
  background: #fff;
  border-radius: 22px;
  padding: 10px 14px;
  font-size: 15.5px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.35;
}

.iconbtn {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  cursor: pointer;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  font-size: 20px;
  color: #54656f;
  border-radius: 50%;
  user-select: none;
}
.iconbtn:hover { background: rgba(0,0,0,0.05); }
.iconbtn:active { background: rgba(0,0,0,0.1); }
.iconbtn.send, .iconbtn.mic {
  background: #128C7E;
  color: #fff;
}
.iconbtn.send:hover, .iconbtn.mic:hover { background: #075E54; }
.iconbtn.mic.recording { background: #d32f2f; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
.iconbtn.attach { color: #54656f; }
.iconbtn.attach input { display: none; }

#resetBtn, #logoutBtn { color: #fff; font-size: 19px; }
#resetBtn:hover, #logoutBtn:hover { background: rgba(255,255,255,0.1); }

@media (max-width: 480px) {
  body { border: none; }
  .bubble { max-width: 88%; font-size: 14.5px; }
}
