.ai-chat-area {
  display: flex !important;
  flex-direction: column-reverse !important;
  justify-content: flex-start !important;
  overflow-y: auto;
  flex: 1 1 auto;
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 18px;
  min-height: 120px;
  color: var(--text-primary);
}

.ai-chat-msg.user {
  align-self: flex-end !important;
  text-align: right !important;
  margin: 8px 0 8px auto !important;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 80%;
  word-break: break-word;
  background: var(--primary-dark);
  color: var(--primary-bright);
}

.ai-chat-msg.assistant {
  align-self: flex-start !important;
  text-align: left !important;
  margin: 8px auto 8px 0 !important;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 80%;
  word-break: break-word;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.ai-chat-msg {
  margin: 8px 0;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 80%;
  word-break: break-word;
}

.ai-chat-area::after {
  content: "";
  display: table;
  clear: both;
}

.ai-chat-loading {
  margin: 8px 0;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 80%;
  background: var(--bg-secondary);
  color: var(--text-muted);
}

/* Modal overlay */
.ai-chat-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  backdrop-filter: none;
}

/* Modal content */
.ai-chat-modal-content {
  background: var(--bg-modal);
  border: 2px solid var(--primary-bright, #00ccad);
  border-radius: 16px;
  box-shadow: 0 4px 32px var(--shadow-heavy);
  padding: 32px 24px 24px 24px;
  min-width: 340px;
  max-width: 50vw;
  width: 100%;
  height: 70vh;
  max-height: 70vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  position: relative;
}

/* Close button */
.ai-chat-close-btn {
  background: none;
  border: none;
  font-size: 32px;
  cursor: pointer;
  color: var(--text-primary);
  opacity: 0.7;
  transition: opacity 0.15s;
  margin-left: 18px;
  width: 64px;
  position: absolute;
  top: 18px;
  right: 18px;
}
.ai-chat-close-btn:hover {
  opacity: 1;
}

/* Title */
.ai-chat-title {
  font-size: 1.3em;
  font-weight: 600;
  margin-bottom: 18px;
  color: var(--accent-orange, #ff6d00);
  letter-spacing: 0.5px;
}

/* Input row */
.ai-chat-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

/* Input field */
.ai-chat-input {
  flex: 1 1 auto;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--border-input);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 1em;
  outline: none;
  min-width: 0;
  box-sizing: border-box;
}

.ai-chat-msg-pair {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 18px;
}

.ai-modal-header-btn {
  background: none;
  border: none;
  color: #fff;
  opacity: 0.7;
  font-size: 24px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.ai-modal-header-btn:hover {
  opacity: 1;
}

.ai-modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(30,30,30,0.97);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Scrollable area: no padding, scrollbar at edge */
.ai-modal-scroll-area {
  flex: 1 1 0%;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 90vh;
  scrollbar-width: thin;
  scrollbar-color: #444 #232323;
  /* No padding here! */
}

.ai-modal-scroll-area::-webkit-scrollbar {
  width: 8px;
  background: #232323;
}
.ai-modal-scroll-area::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 6px;
}
.ai-modal-scroll-area::-webkit-scrollbar-corner {
  background: #232323;
}

/* Inner wrapper: provides content padding */
.ai-modal-scroll-inner {
  padding: 24px 44px;
}

/* Responsive button container */
@media (max-width: 600px) {
  .ai-chat-modal-content {
    min-width: 90vw;
    max-width: 90vw;
    height: 80vh;
    max-height: 80vh;
    padding: 16px 12px 12px 12px;
  }
  
  .ai-modal-scroll-inner {
    padding: 16px 8px;
  }
  
  /* Reduce input row gap on mobile */
  .ai-chat-input-row {
    gap: 8px;
  }
  
  /* Ensure input has proper flex and max width */
  .ai-chat-input {
    flex: 1 1 0;
    min-width: 0;
    max-width: calc(100% - 60px);
  }
  
  /* Stack buttons on mobile */
  .ai-chat-modal-content [style*="display: flex"][style*="flex-wrap: wrap"] {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  
  .ai-chat-modal-content .sidebar-action-btn {
    width: 100% !important;
    margin-bottom: 4px;
  }
}

/* Responsive button styling for AI chat responses */
.ai-chat-response-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.ai-chat-response-buttons .sidebar-action-btn {
  flex: 0 1 auto;
  min-width: 140px;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* On larger screens, try to keep buttons on same row */
@media (min-width: 601px) {
  .ai-chat-response-buttons {
    flex-wrap: nowrap;
  }
  
  .ai-chat-response-buttons .sidebar-action-btn {
    flex: 1 1 0;
    max-width: none;
  }
}

/* On very small screens, stack buttons and further optimize layout */
@media (max-width: 480px) {
  .ai-chat-modal-content {
    min-width: 95vw;
    max-width: 95vw;
    padding: 12px 8px 8px 8px;
  }
  
  .ai-modal-scroll-inner {
    padding: 12px 4px;
  }
  
  /* Further reduce gap and optimize input */
  .ai-chat-input-row {
    gap: 6px;
  }
  
  .ai-chat-input {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 8px 10px;
    max-width: calc(100% - 50px);
  }
  
  .ai-chat-response-buttons {
    flex-direction: column;
  }
  
  .ai-chat-response-buttons .sidebar-action-btn {
    width: 100% !important;
    max-width: none;
  }
}

/* Remove left and right padding from the main modal content container */
.ai-modal-content-large {
  border: 2px solid var(--primary-bright, #00ccad);
  /* Remove any padding-left or padding-right here! */
  padding-left: 0 !important;
  padding-right: 0 !important;
}

/* Utility: flex row with space-between */
.flex-space-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Example usage: <div class="flex-space-between"> ... </div> */

/* Variant: left-aligned modal scroll content, no horizontal padding */
.ai-modal-scroll-inner.ai-modal-scroll-left {
  padding-left: 0;
  padding-right: 0;
  align-items: flex-start;
  display: flex;
  flex-direction: column;
  max-width: 600px; /* or whatever you want for your column */
  /* No width: 100% here! */
}

/* .ai-modal-scroll-inner can be used with or without .ai-modal-scroll-left */

/* ArcGIS Layer Controls */
.ai-layer-controls {
  margin-top: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.layer-control-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.layer-toggle-btn, .layer-remove-btn {
  font-size: 0.9em !important;
  padding: 6px 12px !important;
  min-width: auto !important;
  border-radius: 6px !important;
  transition: all 0.2s ease !important;
}

.layer-toggle-btn {
  background: rgba(0, 204, 173, 0.15) !important;
  color: #00ccad !important;
  border: 1px solid #00ccad !important;
}

.layer-toggle-btn:hover {
  background: rgba(0, 204, 173, 0.25) !important;
}

.layer-remove-btn {
  background: rgba(255, 77, 77, 0.15) !important;
  color: #ff4d4d !important;
  border: 1px solid #ff4d4d !important;
}

.layer-remove-btn:hover {
  background: rgba(255, 77, 77, 0.25) !important;
}

/* Mobile responsiveness for layer controls */
@media (max-width: 480px) {
  .layer-control-group {
    flex-direction: column;
  }
  
  .layer-toggle-btn, .layer-remove-btn {
    width: 100% !important;
    justify-content: center !important;
  }
}
