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

:root {
  --font-body: "Manrope", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --app-bg: radial-gradient(circle at 15% 10%, rgba(18, 140, 126, 0.12), transparent 40%),
    linear-gradient(180deg, #f3f5f2 0%, #eef2ef 60%, #e6ece7 100%);
  --surface: #ffffff;
  --surface-muted: #f6f6f4;
  --accent: #0b6b5f;
  --accent-strong: #064b47;
  --accent-soft: #e7f5f1;
  --text: #1a1f1d;
  --text-muted: #5a6762;
  --border: #d9dedb;
  --shadow-soft: 0 0.75rem 2.25rem rgba(8, 30, 22, 0.12);
  --shadow-card: 0 0.5rem 1.5rem rgba(8, 30, 22, 0.12);
  --radius-xl: 1.25rem;
  --radius-lg: 1rem;
  --radius-md: 0.75rem;
  --radius-pill: 999px;
  --app-height: 100vh;
  --app-top: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --chat-bg: radial-gradient(circle at 25% 10%, rgba(255, 255, 255, 0.7), transparent 55%),
    radial-gradient(circle at 85% 15%, rgba(11, 107, 95, 0.08), transparent 45%),
    #ece5dd;
}

@supports (height: 100dvh) {
  :root {
    --app-height: 100dvh;
  }
}

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

html {
  width: 100%;
  height: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--app-bg);
  color: var(--text);
  width: 100%;
  height: var(--app-height);
  min-height: var(--app-height);
  margin: 0;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: stretch;
  overscroll-behavior: none;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

.login-modal,
.contact-modal {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(9, 16, 14, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: clamp(1rem, 4vw, 2rem);
  z-index: 1000;
}

.login-modal.hidden,
.contact-modal.hidden {
  display: none;
}

.login-container,
.contact-card {
  background: var(--surface);
  padding: clamp(1.5rem, 4vw, 2.5rem);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 26rem;
  box-shadow: var(--shadow-card);
}

.login-container h2,
.contact-header {
  margin-bottom: 1rem;
  text-align: center;
  color: var(--accent);
  font-size: clamp(1.25rem, 2.8vw, 1.5rem);
  font-weight: 700;
}

.login-container .form-group {
  margin-bottom: 1rem;
}

.login-container label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
}

.login-container input,
.contact-card input,
.contact-card textarea {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  background: #fff;
}

.login-container button,
.contact-card button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  min-height: 2.75rem;
}

.login-container button:hover,
.contact-card button:hover {
  background: var(--accent-strong);
}

.login-container button:active,
.contact-card button:active {
  transform: translateY(1px);
}

.login-error {
  color: #c62828;
  font-size: 0.85rem;
  margin-top: 0.5rem;
  text-align: center;
}

.contact-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chat-wrapper {
  display: flex;
  flex-direction: column;
  width: min(100%, 42rem);
  height: var(--app-height);
  background: var(--surface);
  overflow: hidden;
  position: fixed;
  top: var(--app-top);
  left: 50%;
  transform: translateX(-50%);
  margin: 0 auto;
  z-index: 100;
  min-height: 0;
}

.chat-wrapper.hidden {
  display: none;
}

.chat-header {
  background: linear-gradient(135deg, #0a5b50 0%, #18a189 100%);
  color: #fff;
  padding: calc(0.75rem + var(--safe-top)) 1rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.profile-pic {
  position: relative;
  width: clamp(2.4rem, 6vw, 2.8rem);
  height: clamp(2.4rem, 6vw, 2.8rem);
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-weight: 700;
  color: var(--accent);
}

.profile-pic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.profile-pic .fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e8f4ef;
  color: var(--accent);
}

.header-info h3 {
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  margin-bottom: 0.1rem;
}

.header-info p {
  font-size: 0.75rem;
  opacity: 0.85;
}

.header-right {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.header-btn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 50%;
  min-width: 2.75rem;
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.icon-img {
  width: 1.25rem;
  height: 1.25rem;
  object-fit: contain;
  display: block;
}

.menu-wrapper {
  position: relative;
}

.menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  min-width: 11rem;
  overflow: hidden;
  z-index: 10;
}

.menu-dropdown button {
  background: none;
  border: none;
  padding: 0.75rem 0.9rem;
  text-align: left;
  cursor: pointer;
}

.menu-dropdown button:hover {
  background: var(--surface-muted);
}

.messages-area {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: clamp(0.75rem, 3vw, 1.25rem);
  background: var(--chat-bg);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  overscroll-behavior: contain;
}

.message-group {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.message-group.user {
  justify-content: flex-end;
  flex-direction: row-reverse;
}

.message-group.user .message-bubble {
  margin-left: auto;
}

.message-bubble,
.message-content,
.message-reply-ref {
  user-select: none;
}

.avatar {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  overflow: hidden;
  background: #18a189;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
}

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

.message-group.user .avatar {
  display: none;
}

.message-bubble {
  max-width: min(85%, 32rem);
  padding: 0.6rem 0.75rem;
  border-radius: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.message-group.assistant .message-bubble {
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 0.4rem 1.1rem rgba(0, 0, 0, 0.08);
}

.message-group.user .message-bubble {
  background: #dcf8c6;
  box-shadow: 0 0.4rem 1.1rem rgba(0, 0, 0, 0.08);
}

.message-content {
  font-size: clamp(0.95rem, 2.4vw, 1rem);
  line-height: 1.45;
  word-break: break-word;
  overflow-wrap: break-word;
}

.inline-code {
  background: rgba(0, 0, 0, 0.06);
  padding: 0.15rem 0.35rem;
  border-radius: 0.35rem;
  font-family: "SFMono-Regular", "Fira Code", "Consolas", "Menlo", monospace;
  font-size: 0.85em;
}

.message-time {
  font-size: 0.7rem;
  opacity: 0.7;
  text-align: right;
}

.message-reply-ref {
  font-size: 0.72rem;
  background: rgba(0, 0, 0, 0.04);
  padding: 0.4rem 0.5rem;
  border-left: 0.2rem solid var(--accent);
  border-radius: 0.4rem;
  color: var(--text);
}

.message-status {
  font-size: 0.7rem;
  color: #2e7d32;
  text-align: right;
}

.voice-message {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.04);
  padding: 0.5rem;
  border-radius: 0.7rem;
}

.voice-play {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.voice-wave {
  flex: 1;
  height: 1rem;
  background: linear-gradient(90deg, #2e7d32 10%, #66bb6a 30%, #2e7d32 50%, #1b5e20 70%, #66bb6a 90%);
  border-radius: 0.6rem;
  opacity: 0.8;
  position: relative;
  overflow: hidden;
}

.voice-progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: rgba(255, 255, 255, 0.4);
  width: 0%;
  transition: width 0.1s linear;
}

.voice-duration {
  font-size: 0.7rem;
  opacity: 0.8;
  width: 3rem;
  text-align: right;
}

.typing-indicator {
  display: flex;
  gap: 0.3rem;
  padding: 0.6rem 0.75rem;
}

.typing-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #999;
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    opacity: 0.3;
  }
  30% {
    opacity: 1;
  }
}

.input-area {
  padding: 0.75rem 0.75rem calc(0.75rem + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(246, 247, 245, 0.95) 0%, rgba(240, 242, 239, 0.98) 100%);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

.input-wrapper {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.input-box {
  flex: 1;
  background: #fff;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  box-shadow: 0 0.35rem 1rem rgba(0, 0, 0, 0.1);
  border: 1px solid transparent;
}

.input-box textarea {
  flex: 1;
  border: none;
  padding: 0.5rem 0.4rem;
  font-size: clamp(0.95rem, 2.4vw, 1rem);
  outline: none;
  resize: none;
  max-height: 8.5rem;
  min-height: 2.75rem;
  background: transparent;
  color: #000;
  width: 100%;
  line-height: 1.5;
  overflow-y: auto;
}

.voice-btn {
  display: none;
}

.send-btn {
  background: var(--accent);
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  min-width: 2.75rem;
  min-height: 2.75rem;
  box-shadow: 0 0.35rem 1rem rgba(0, 0, 0, 0.12);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  touch-action: manipulation;
}

.send-btn:active {
  transform: scale(0.97);
}

.send-btn .icon-img {
  filter: brightness(0) invert(1);
}

.reply-indicator {
  background: #fff;
  border-left: 0.2rem solid var(--accent);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.reply-close {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: #888;
}

.recording-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #ffe8e8;
  border: 1px solid #f5b5b5;
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
}

.recording-bar.hidden {
  display: none;
}

.recording-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: #d32f2f;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

.contact-modal .contact-card input,
.contact-modal .contact-card textarea {
  margin-bottom: 0.5rem;
}

.copy-modal {
  position: fixed;
  background: rgba(12, 12, 12, 0.9);
  color: #fff;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  z-index: 2000;
  pointer-events: none;
  white-space: nowrap;
  max-width: 12rem;
  text-align: center;
  display: none;
  transform: translate(-50%, -120%);
  box-shadow: 0 0.6rem 1.5rem rgba(0, 0, 0, 0.3);
}

.copy-modal.show {
  display: block;
  pointer-events: auto;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -120%) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -120%) scale(1);
  }
}

.swipe-transform {
  transition: transform 0.12s ease-out;
}

.hidden {
  display: none !important;
}

@media (min-width: 768px) {
  .chat-wrapper {
    box-shadow: var(--shadow-soft);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
  }

  .messages-area {
    padding: clamp(1rem, 2vw, 1.5rem);
  }
}
