*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --green: #25D366;
  --green-dark: #1aab52;
  --green-light: #dcf8c6;
  --bg: #f0f2f5;
  --white: #ffffff;
  --bubble-in: #ffffff;
  --bubble-out: #dcf8c6;
  --text: #111b21;
  --text-muted: #667781;
  --border: #e9edef;
  --header-bg: #ffffff;
  --input-bg: #f0f2f5;
  --radius: 12px;
}

html, body {
  height: 100%;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.screen { display: none; }
.screen.active { display: flex; }

#login-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  animation: fadeIn 0.3s ease;
}

.login-box {
  background: var(--white);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.login-logo {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.login-title {
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.5px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: -8px;
  margin-bottom: 6px;
}

.login-box input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  background: var(--input-bg);
  outline: none;
  transition: border-color 0.2s;
}

.login-box input:focus {
  border-color: var(--green);
  background: #fff;
}

.login-error {
  font-size: 13px;
  color: #e53935;
  text-align: center;
  min-height: 18px;
  width: 100%;
}

.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover { background: var(--green-dark); }
.btn-primary:active { transform: scale(0.98); }

.login-toggle {
  font-size: 13px;
  color: var(--text-muted);
}

.btn-link {
  background: none;
  border: none;
  color: var(--green);
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  font-weight: 500;
  margin-left: 4px;
  text-decoration: underline;
}

#chat-screen {
  flex-direction: column;
  height: 100vh;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
  background: var(--white);
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

.header-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.header-status {
  font-size: 12px;
  color: var(--green);
  margin-top: 1px;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-icon:hover { background: var(--bg); }

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #efeae2;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c9bfb0' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #9e9e9e;
  font-size: 14px;
}

.empty-state svg { opacity: 0.4; }

.msg-row {
  display: flex;
  animation: msgIn 0.15s ease;
}

.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

.bubble {
  max-width: 68%;
  padding: 8px 12px 6px;
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.msg-row.mine .bubble {
  background: var(--bubble-out);
  color: #111;
  border-bottom-right-radius: 3px;
}

.msg-row.theirs .bubble {
  background: var(--bubble-in);
  color: var(--text);
  border-bottom-left-radius: 3px;
}

.bubble-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--green-dark);
  margin-bottom: 3px;
}

.bubble-text { white-space: pre-wrap; }

.bubble-time {
  font-size: 11px;
  color: #8a9299;
  text-align: right;
  margin-top: 3px;
}

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 16px;
  background: var(--header-bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#msg-input {
  flex: 1;
  padding: 10px 16px;
  border-radius: 24px;
  border: none;
  background: var(--input-bg);
  font-size: 15px;
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
}

#msg-input:focus {
  box-shadow: 0 0 0 2px rgba(37,211,102,0.25);
}

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--green);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.btn-send:hover { background: var(--green-dark); }
.btn-send:active { transform: scale(0.95); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.messages-area::-webkit-scrollbar { width: 5px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: #ccc; border-radius: 10px; }

@media (max-width: 600px) {
  #chat-screen { max-width: 100%; }
  .bubble { max-width: 82%; }
  .login-box { margin: 1rem; padding: 2rem 1.5rem; }
}