@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;600;700&display=swap');

:root {
  color-scheme: light;
  --whatsapp-header: #075E54;
  --whatsapp-accent: #25D366;
  --whatsapp-bg: #ECE5DD;
  --message-incoming: #ffffff;
  --message-outgoing: #DCF8C6;
  --text: #0f1e1a;
  --muted: rgba(255, 255, 255, 0.72);
  --app-height: 100vh;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  width: 100%;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: 'Manrope', sans-serif;
  background: #0b141a;
  color: var(--text);
  overflow: hidden;
  height: var(--app-height);
  touch-action: manipulation;
}

.app {
  display: flex;
  flex-direction: column;
  height: var(--app-height);
  min-height: var(--app-height);
  background: var(--whatsapp-bg);
}

.app__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 20px 16px;
  background: linear-gradient(110deg, var(--whatsapp-header), var(--whatsapp-accent));
  color: #fff;
  position: relative;
  z-index: 2;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.app__avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}

.app__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app__info {
  flex: 1;
}

.app__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.app__subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.status {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--whatsapp-accent);
  color: #0b1a16;
  font-weight: 600;
  white-space: nowrap;
}

.chat {
  position: relative;
  flex: 1;
  display: flex;
  min-height: 0;
}

.chat__background {
  position: absolute;
  inset: 0;
  background-color: var(--whatsapp-bg);
  background-image:
    radial-gradient(circle at 25px 25px, rgba(255, 255, 255, 0.6) 0, rgba(255, 255, 255, 0.6) 1px, transparent 1px),
    radial-gradient(circle at 75px 75px, rgba(255, 255, 255, 0.35) 0, rgba(255, 255, 255, 0.35) 1px, transparent 1px);
  background-size: 100px 100px;
  opacity: 0.45;
}

.chat__messages {
  position: relative;
  z-index: 1;
  flex: 1;
  padding: 10px 8px 6px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
}

.chat__empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: rgba(15, 30, 26, 0.6);
  font-size: 14px;
  z-index: 1;
}

.message {
  display: flex;
}

.message--incoming {
  justify-content: flex-start;
}

.message--outgoing {
  justify-content: flex-end;
}

.message__bubble {
  max-width: min(78%, 520px);
  padding: 6px 8px;
  border-radius: 12px;
  background: var(--message-incoming);
  box-shadow: 0 6px 16px rgba(15, 30, 26, 0.08);
  position: relative;
}

.message--outgoing .message__bubble {
  background: var(--message-outgoing);
}

.message__text {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.message__attachments {
  margin-top: 3px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.05);
  color: inherit;
  text-decoration: none;
  font-size: 13px;
}

.attachment img {
  max-width: 200px;
  border-radius: 10px;
  display: block;
}

.attachment audio {
  width: 200px;
}

.message__meta {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  color: rgba(15, 30, 26, 0.6);
  text-align: right;
}

.composer {
  border-top: 1px solid rgba(15, 30, 26, 0.1);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  z-index: 2;
}

.composer__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer__field {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: none;
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  box-shadow: 0 6px 12px rgba(15, 30, 26, 0.08);
}

.icon-button.is-recording {
  background: #ff6b6b;
  color: #fff;
}

.icon-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#messageInput {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid rgba(15, 30, 26, 0.1);
  font-size: 15px;
  resize: none;
  font-family: inherit;
}

#messageInput:disabled {
  background: rgba(15, 30, 26, 0.05);
  color: rgba(15, 30, 26, 0.6);
}

.composer__preview {
  flex: 1;
  min-height: 38px;
  padding: 4px 8px;
  border-radius: 14px;
  border: 1px solid rgba(15, 30, 26, 0.12);
  background: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 12px rgba(15, 30, 26, 0.06);
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.composer__preview .file-name {
  flex: 1;
  font-size: 14px;
  color: rgba(15, 30, 26, 0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.audio-play {
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--whatsapp-accent);
  color: #0b1a16;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#audioProgress {
  flex: 1;
  min-width: 0;
  height: 6px;
  accent-color: var(--whatsapp-accent);
}

.audio-time {
  font-size: 12px;
  color: rgba(15, 30, 26, 0.7);
  white-space: nowrap;
  flex-shrink: 0;
}

#audioPlayer {
  display: none;
}

.preview-cancel {
  border: none;
  background: rgba(15, 30, 26, 0.1);
  color: #1b2b27;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.send-button {
  border: none;
  background: var(--whatsapp-accent);
  color: #0b1a16;
  padding: 10px 14px;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
}

.send-button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.composer__status {
  margin-top: 6px;
  font-size: 12px;
  color: rgba(15, 30, 26, 0.65);
  font-weight: 600;
}


.modal {
  position: fixed;
  inset: 0;
  background: rgba(11, 20, 26, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 24px;
}

.modal.hidden {
  display: none;
}

.modal__card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.modal__card h2 {
  margin: 0 0 8px;
}

.modal__card p {
  margin: 0 0 18px;
  color: rgba(15, 30, 26, 0.6);
}

#nameForm {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#nameForm input {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(15, 30, 26, 0.12);
  font-size: 15px;
  font-family: inherit;
}

.phone-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.phone-field label {
  font-size: 13px;
  font-weight: 600;
  color: rgba(15, 30, 26, 0.75);
}

.phone-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 6px;
}

.select-wrap {
  position: relative;
  min-width: 0;
}

.select-display {
  display: flex;
  align-items: center;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid rgba(15, 30, 26, 0.12);
  font-size: 14px;
  background: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.select-wrap select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.phone-row select,
.phone-row input {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(15, 30, 26, 0.12);
  font-size: 14px;
  font-family: inherit;
}

.phone-hint {
  margin: 0;
  font-size: 12px;
  color: rgba(15, 30, 26, 0.55);
}

@media (max-width: 640px) {
  .phone-row {
    grid-template-columns: 80px 1fr;
  }
}

#nameForm button {
  border: none;
  background: var(--whatsapp-accent);
  color: #0b1a16;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 640px) {
  .app__header {
    padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  }

  .status {
    display: none;
  }

  .chat__messages {
    padding: 12px 10px 8px;
  }

  .composer {
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  }

  .send-button {
    padding: 10px 12px;
  }
}
