:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-color: #f1f5f9;
  --surface-color: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --bot-msg-bg: #e2e8f0;
  --user-msg-bg: #2563eb;
  --user-msg-text: #ffffff;
  --border-radius: 12px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

body {
  font-family: 'Inter', 'Mukta Malar', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-size: 1.125rem; /* 18px text baseline for accessibility */
}

/* Accessibility: Hide default elements appropriately, but preserve semantic meaning */
.hidden {
  display: none !important;
}

body.lang-ta .text-en { display: none; }
body:not(.lang-ta) .text-ta { display: none; }

/* Header Elements */
.app-header {
  background: var(--surface-color);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
  z-index: 10;
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-color);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Lang Switch Toggle */
.lang-switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
}
.lang-switch input {
  display: none;
}
.slider {
  position: relative;
  width: 44px;
  height: 24px;
  background-color: #cbd5e1;
  border-radius: 34px;
  transition: .4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: .4s;
}
input:checked + .slider {
  background-color: var(--primary-color);
}
input:checked + .slider:before {
  transform: translateX(20px);
}

/* Base Buttons */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--border-radius);
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  transition: background-color 0.2s, transform 0.1s;
}
button:active {
  transform: scale(0.98);
}
.btn-primary, #btn-send-message, #btn-send-otp, #btn-verify-otp, #btn-submit-author-question {
  background-color: var(--primary-color);
  color: #fff;
}
.btn-primary:hover, #btn-send-message:hover {
  background-color: var(--primary-hover);
}

/* Main Layout container */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

/* Auth Section */
#auth-section {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  padding: 2rem;
  text-align: center;
}
.input-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
  width: 100%;
  max-width: 320px;
}
input[type="tel"], input[type="text"], select {
  padding: 1rem;
  border-radius: var(--border-radius);
  border: 1px solid #cbd5e1;
  font-size: 1.125rem;
  font-family: inherit;
  text-align: center;
}

.phone-input-container {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

#country-code {
  width: 140px;
  text-align: left;
  padding: 0.5rem;
  font-size: 0.9rem;
}

#phone-number {
  flex: 1;
}

.spam-disclaimer {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: -0.5rem;
  font-style: italic;
}

/* Chat Section */
#chat-section {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.message {
  max-width: 85%;
  padding: 1rem 1.25rem;
  border-radius: 1.25rem;
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeIn 0.3s ease;
}
.bot-message {
  align-self: flex-start;
  background-color: var(--bot-msg-bg);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
}
.user-message {
  align-self: flex-end;
  background-color: var(--user-msg-bg);
  color: var(--user-msg-text);
  border-bottom-right-radius: 4px;
}
.system-message {
    align-self: center;
    background-color: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-style: italic;
    text-align: center;
}

.chat-input-area {
  padding: 1rem 1.5rem;
  background: var(--surface-color);
  box-shadow: 0 -1px 3px 0 rgb(0 0 0 / 0.1);
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}
.chat-input-area textarea {
  flex: 1;
  resize: none;
  font-family: inherit;
  font-size: 1.125rem;
  padding: 0.75rem 1rem;
  border-radius: var(--border-radius);
  border: 1px solid #cbd5e1;
  height: 50px;
  max-height: 120px;
  overflow-y: auto;
}
.char-counter {
  text-align: right;
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 0.25rem 1.5rem 0.75rem;
  background: var(--surface-color);
  margin-top: -5px; /* compact spacing */
}

/* Modals */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s;
}
.modal-content {
  background: var(--surface-color);
  padding: 2rem;
  border-radius: var(--border-radius);
  width: 90%;
  max-width: 450px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
  box-shadow: var(--shadow);
}
.close-btn {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  font-size: 1.75rem;
  cursor: pointer;
  color: var(--text-muted);
}
.modal-content textarea {
  font-family: inherit;
  font-size: 1.125rem;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  resize: vertical;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
  .app-header {
    flex-wrap: wrap; /* allow wrapping if title is long */
    padding: 0.75rem 1rem;
  }
  .app-header h1 {
    font-size: 1.125rem;
  }
  .header-controls {
    margin-top: 0.5rem;
    width: 100%;
    justify-content: space-between;
  }
  .chat-input-area {
    padding: 0.75rem 1rem;
  }
}
