/* ==========================================================================
   GramShala AI Assistant Stylesheet
   Philosophy: Minimal, Professional, Restrained Civic Interface
   ========================================================================== */

.gs-chat {
  /* Palette aligned to GramShala (Rural Karnataka Civic-Tech) */
  --color-primary: #3A4B33;
  --color-primary-dark: #2F3D2A;
  --color-primary-subtle: #EBF0E7;

  --color-accent: #672D3D;

  /* Surfaces & Neutrals */
  --bg-page: #F5F0E5;
  --bg-surface: #FAF7F0;
  --bg-subtle: #F5F0E5;
  --border-subtle: #D8CEB9;
  --border-medium: #C6D1BE;

  /* Typography */
  --text-primary: #222B1E;
  --text-secondary: #4B5646;
  --text-muted: #6D7768;
  --text-white: #ffffff;

  /* Chat Specific */
  --user-bubble-bg: #3A4B33;
  --user-bubble-text: #ffffff;
  --ai-bubble-bg: #ffffff;
  --ai-bubble-border: #D8CEB9;
  --ai-bubble-text: #222B1E;

  /* Layout & Geometry */
  --header-height: 56px;
  --max-content-width: 900px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

/* Scoped reset for embedded chatbot */
.gs-chat,
.gs-chat *,
.gs-chat *::before,
.gs-chat *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.gs-chat {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* App Main Container */
.app-container {
  display: flex;
  flex-direction: column;
  height: min(80vh, 720px);
  min-height: 480px;
  max-width: var(--max-content-width);
  margin: 0 auto;
  background: var(--bg-surface);
  position: relative;
  overflow: hidden;
}

/* ==========================================================================
   Header Styles
   ========================================================================== */
.chat-header {
  height: var(--header-height);
  background-color: #233221;
  color: var(--text-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 20;
  border-bottom: 1px solid #2F3D2A;
  flex-shrink: 0;
}

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

.chat-brand-mark {
  background: #ffffff;
  color: #233221;
  width: 28px;
  height: 28px;
  font-size: 14px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
}

.brand-info {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #b7cebf;
}

.status-dot {
  width: 7px;
  height: 7px;
  background-color: #4ade80;
  border-radius: 50%;
  display: inline-block;
}

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

/* Language Dropdown */
.language-dropdown-wrapper {
  position: relative;
}

.custom-select {
  position: relative;
  display: flex;
  align-items: center;
}

.custom-select select {
  background-color: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  appearance: auto;
}

.custom-select select option {
  background-color: #233221;
  color: #ffffff;
}

.custom-select select:hover,
.custom-select select:focus {
  background-color: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.45);
}

/* Clear Chat Button */
.action-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  border-radius: var(--radius-sm);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   Chat Viewport & Welcome Screen
   ========================================================================== */
.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  background-color: var(--bg-subtle);
  position: relative;
}

.welcome-screen {
  padding: 12px 4px;
  display: flex;
  justify-content: center;
}

.welcome-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  text-align: center;
  max-width: 640px;
  width: 100%;
}

.welcome-badge {
  display: inline-flex;
  align-items: center;
  background: var(--primary-subtle);
  color: var(--color-primary);
  border: 1px solid var(--border-subtle);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.welcome-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  line-height: 1.35;
}

.welcome-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.suggested-questions-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-accent);
  margin-bottom: 10px;
  text-align: left;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px;
}

.suggestion-chip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  line-height: 1.45;
}

.suggestion-chip .chip-icon {
  color: var(--color-accent);
  flex-shrink: 0;
  margin-top: 1px;
  display: inline-flex;
}

.suggestion-chip:hover {
  background: var(--primary-subtle);
  border-color: var(--color-primary);
}

/* ==========================================================================
   Messages Area & Bubbles
   ========================================================================== */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message-row {
  display: flex;
  width: 100%;
}

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

.message-row.assistant {
  justify-content: flex-start;
  gap: 8px;
}

.ai-avatar-badge {
  width: 26px;
  height: 26px;
  background-color: var(--color-primary);
  color: #ffffff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.avatar-letter {
  display: inline-block;
  line-height: 1;
}

.message-bubble {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  position: relative;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.55;
}

.message-row.user .message-bubble {
  background-color: var(--user-bubble-bg);
  color: var(--user-bubble-text);
  border-radius: var(--radius-md) var(--radius-md) 2px var(--radius-md);
}

.message-row.assistant .message-bubble {
  background-color: var(--ai-bubble-bg);
  color: var(--ai-bubble-text);
  border: 1px solid var(--ai-bubble-border);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 2px;
}

.bubble-text p {
  margin-bottom: 6px;
}
.bubble-text p:last-child {
  margin-bottom: 0;
}
.bubble-text ul, .bubble-text ol {
  margin: 4px 0 6px 18px;
  padding: 0;
}
.bubble-text li {
  margin-bottom: 3px;
}
.bubble-text strong {
  font-weight: 600;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
  font-size: 11px;
}
.message-row.user .message-meta {
  color: rgba(255, 255, 255, 0.75);
}
.message-row.assistant .message-meta {
  color: var(--text-muted);
}

.copy-btn, .speak-btn {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 2px 4px;
  opacity: 0.7;
  transition: opacity 0.15s;
  display: inline-flex;
  align-items: center;
}
.copy-btn:hover, .speak-btn:hover {
  opacity: 1;
}
.speak-btn.speaking {
  color: var(--color-accent);
  opacity: 1;
}

/* Typing Indicator */
.typing-indicator-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}
.typing-bubble {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.typing-bubble .dot {
  width: 5px;
  height: 5px;
  background-color: var(--color-primary);
  border-radius: 50%;
  display: inline-block;
  opacity: 0.6;
}
.typing-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 4px;
}

/* ==========================================================================
   Chat Input Area
   ========================================================================== */
.chat-input-area {
  padding: 10px 14px 12px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.input-form {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 4px 6px 4px 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-form:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(22, 101, 52, 0.12);
}

.input-wrapper {
  flex: 1;
}

textarea#messageInput {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  max-height: 100px;
  min-height: 22px;
  line-height: 1.4;
  padding: 4px 0;
  overflow-y: auto;
}

textarea#messageInput::placeholder {
  color: var(--text-muted);
}

/* Voice & Send Buttons */
.voice-btn {
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.voice-btn:hover {
  background: var(--primary-subtle);
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.voice-btn.listening {
  background: #F6EDF0;
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.send-button {
  background-color: var(--color-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease;
}
.send-button:hover:not(:disabled) {
  background-color: var(--color-primary-dark);
}
.send-button:disabled {
  background-color: var(--border-subtle);
  color: var(--text-muted);
  cursor: not-allowed;
}
.send-icon {
  width: 15px;
  height: 15px;
}

.voice-status {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 4px;
  min-height: 16px;
}

.input-disclaimer {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 6px;
  line-height: 1.35;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .chat-header {
    height: 52px;
    padding: 0 10px;
  }
  .app-container {
    height: min(82vh, 660px);
  }
  .suggestions-grid {
    grid-template-columns: 1fr;
  }
  .welcome-card {
    padding: 16px 12px;
  }
}
