:root {
  --ktr-green: #00625f;
  --ktr-green-dark: #004f4b;
  --ktr-green-light: #6bbaae;
  --bg: #f1f5f9;
  --assistant-bg: #e6f4f2;
  --user-bg: #d1faf0;
  --link: var(--ktr-green);
}

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

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  font-family: "Inter", system-ui, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  overflow: hidden;
}

/* Chat Container */
#chat-wrapper {
  width: 100%;
  max-width: 700px;
  height: 90vh;
  margin: 0 1rem;
  background: white;
  display: flex;
  flex-direction: column;
  border-radius: 1.2rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  overflow: hidden;
  position: relative;
}

header {
  background: var(--ktr-green);
  color: white;
  text-align: center;
  padding: 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: #ffffff;
}

.msg {
  max-width: 75%;
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  animation: fadeIn 0.2s ease;
}

.msg.user {
  background: var(--user-bg);
  align-self: flex-end;
  border-bottom-right-radius: 0.3rem;
}

.msg.assistant {
  background: var(--assistant-bg);
  align-self: flex-start;
  border-bottom-left-radius: 0.3rem;
}

.msg h2 {
  font-size: 1.1rem;
  margin: 0.3rem 0 0.6rem 0;
  padding-bottom: 0.3rem;
  border-bottom: 3px solid var(--ktr-green);
  font-weight: 700;
  color: var(--ktr-green-dark);
}

.msg strong {
  font-weight: 700;
  color: #000;
}

.msg a {
  color: var(--link);
  font-weight: 600;
  text-decoration: none;
  transition: 0.2s ease;
  word-break: break-word;
}

.msg a:hover {
  color: var(--ktr-green-dark);
  text-decoration: underline;
}

.msg a.mailto-btn {
  display: inline-block;
  padding: 6px 12px;
  margin-top: 6px;
  background: var(--ktr-green);
  color: white !important;
  border-radius: 6px;
  font-size: 0.85rem;
  text-decoration: none !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  white-space: nowrap;
  cursor: pointer;
}

.msg a.mailto-btn:hover {
  background: var(--ktr-green-dark);
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  text-decoration: none !important;
}

/* Sent badge styling */
.msg a.mailto-btn.sent {
  background: #16a34a;
}

.msg a.mailto-btn.sent::after {
  content: " ✓";
  font-weight: 700;
}

.thinking {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  opacity: 0.8;
  font-style: italic;
}

.dots span {
  width: 6px;
  height: 6px;
  display: inline-block;
  background: var(--ktr-green-dark);
  border-radius: 50%;
  margin-right: 3px;
  animation: blink 1.4s infinite both;
}

.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0% { opacity: .2; }
  20% { opacity: 1; }
  100% { opacity: .2; }
}

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

#input-area {
  border-top: 1px solid #e2e8f0;
  padding: 1rem;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex-shrink: 0;
}

#file-input {
  display: none;
}

#file-label {
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--ktr-green);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

#file-list {
  font-size: 0.8rem;
  color: var(--ktr-green-dark);
  word-break: break-word;
}

textarea {
  width: 100%;
  min-height: 3.2rem;
  max-height: 10rem;
  resize: vertical;
  padding: 0.8rem;
  border-radius: 0.7rem;
  border: 1px solid #cbd5e1;
  font-family: inherit;
  font-size: 0.95rem;
}

#button-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

button {
  background: var(--ktr-green);
  border: none;
  padding: 0.7rem 1.2rem;
  border-radius: 0.8rem;
  color: white;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  transition: 0.2s ease;
  max-width: 100%;
  white-space: nowrap;
}

button:hover {
  background: var(--ktr-green-dark);
  transform: translateY(-1px);
}

#share-status {
  font-size: 0.8rem;
  color: var(--ktr-green-dark);
  min-height: 1em;
  word-break: break-word;
}

#email-send-status {
  font-size: 0.8rem;
  color: #475569;
  min-height: 1em;
}

#email-send-status.success {
  color: #15803d;
}

#email-send-status.error {
  color: #b91c1c;
}

/* Modal styles */
#email-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

#email-modal-backdrop.visible {
  display: flex;
}

#email-modal {
  background: #ffffff;
  border-radius: 0.9rem;
  padding: 1.1rem 1.2rem;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

#email-modal h3 {
  margin: 0;
  font-size: 1rem;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#email-modal p {
  margin: 0;
  font-size: 0.85rem;
  color: #475569;
}

#modal-user-email {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid #cbd5e1;
  font-size: 0.9rem;
}

#email-modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.btn-secondary {
  background: #e2e8f0;
  color: #0f172a;
}

.btn-secondary:hover {
  background: #cbd5e1;
  transform: none;
}

#modal-error {
  font-size: 0.8rem;
  color: #b91c1c;
  min-height: 1em;
}
