/* ——— GeoAI Page Layout & Styling ——— */

/* Full Viewport Reset for GeoAI Application (Scoped to GeoAI Page) */
body:has(.geoai-page),
body:has(.geoai-page) #app-content-wrapper,
body:has(.geoai-page) #inner-app-content,
body:has(.geoai-page) #app-content,
.geoai-page {
  height: 100% !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  left: 0 !important;
  right: 0 !important;
  top: 0 !important;
  bottom: 0 !important;
  overflow: hidden !important;
  float: none !important;
}

.geoai-page {
  box-sizing: border-box;
  display: flex !important;
  flex-direction: column !important;
  height: 100% !important;
  overflow: hidden !important;
  background: #f1f5f9;
}

/* Page Header */
.geoai-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.35rem clamp(0.75rem, 3vw, 1.25rem);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
}

.geoai-header .icimod-logo-wrap,
.geoai-header .icimod-mode-nav {
  position: static;
  flex: 0 0 auto;
  pointer-events: auto;
}

.geoai-page-title {
  margin: 0;
  flex: 1 1 auto;
  text-align: center;
  font-size: clamp(1.15rem, 2.2vw, 1.45rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #0f172a;
}

/* Two-Column Layout Container */
.geoai-columns {
  display: flex !important;
  flex-direction: row !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: calc(100% - 60px) !important;
  overflow: hidden !important;
  gap: 0;
  background: #e2e8f0;
}

/* Left Column: Map & Controls */
.geoai-map-column {
  flex: 0 0 70% !important;
  width: 70% !important;
  max-width: 70% !important;
  display: flex !important;
  flex-direction: column !important;
  height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
  background: #fff;
  border-right: 1px solid #cbd5e1;
}

.geoai-map-toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
}

.geoai-toolbar-label {
  font-size: 0.8rem;
  color: #64748b;
  margin: 0;
}

.geoai-select {
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
}

.geoai-geocode-form {
  display: flex;
  flex: 1 1 auto;
  min-width: 140px;
  max-width: min(420px, 100%);
  gap: 0.35rem;
  margin-left: auto;
}

.geoai-geocode-input {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.85rem;
  padding: 0.38rem 0.55rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
}

.geoai-geocode-status {
  flex: 1 1 100%;
  font-size: 0.78rem;
  color: #64748b;
  min-height: 1.1em;
}

.geoai-map {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: 100% !important;
  width: 100% !important;
  position: relative !important;
  overflow: hidden;
  background: #e5e7eb;
}

.geoai-attribution {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.35rem 0.65rem;
  font-size: 0.72rem;
  color: #64748b;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
}

.geoai-attribution a {
  color: #2563eb;
}

/* Right Column: LLM Chat Agent */
.geoai-llm-column {
  flex: 0 0 30% !important;
  width: 30% !important;
  max-width: 30% !important;
  display: flex !important;
  flex-direction: column !important;
  height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  padding: 0.75rem !important;
  gap: 0 !important;
  background: #f8fafc !important;
}

.chat-header {
  background: #1e293b;
  color: #ffffff;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  flex: 0 0 auto !important;
}

.chat-header-title {
  font-weight: 600;
  font-size: 0.88rem;
  letter-spacing: 0.01em;
}

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

.trace-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 0.74rem;
  font-weight: 500;
  color: #94a3b8;
  transition: color 0.2s ease;
}

.trace-toggle-label:hover {
  color: #f1f5f9;
}

.trace-toggle-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.trace-toggle-switch {
  position: relative;
  display: inline-block;
  width: 26px;
  height: 14px;
  background-color: #475569;
  border-radius: 14px;
  transition: background-color 0.2s ease;
}

.trace-toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.trace-toggle-label input[type="checkbox"]:checked + .trace-toggle-switch {
  background-color: #0284c7;
}

.trace-toggle-label input[type="checkbox"]:checked + .trace-toggle-switch::after {
  transform: translateX(12px);
}

.trace-toggle-label input[type="checkbox"]:checked ~ .trace-toggle-text {
  color: #e2e8f0;
}

.trace-toggle-text {
  font-size: 0.72rem;
}

.chat-header .status {
  font-size: 0.7rem;
  background: #10b981;
  color: white;
  padding: 2px 6px;
  border-radius: 12px;
}

.chat-messages {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  padding: 12px;
  overflow-y: auto !important;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 1px solid #cbd5e1;
  border-right: 1px solid #cbd5e1;
}

/* Hide agent thoughts card entirely when trace is disabled */
.chat-messages.hide-agent-trace .agent-thoughts-card {
  display: none !important;
}

.message {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.user-message {
  background: #3b82f6;
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.bot-message {
  background: #e2e8f0;
  color: #1e293b;
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

/* Agent Thoughts & MCP Execution Trace Card */
.agent-thoughts-card {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  margin-bottom: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
}

.agent-thoughts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #f1f5f9;
  cursor: pointer;
  user-select: none;
  font-size: 0.76rem;
  color: #475569;
  font-weight: 500;
  border-bottom: 1px solid #e2e8f0;
}

.agent-thoughts-header:hover {
  background: #e2e8f0;
}

.agent-thoughts-title {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.3;
  flex: 1 1 auto;
}

.agent-brain-icon {
  color: #64748b;
  flex-shrink: 0;
}

.agent-thoughts-toggle-btn {
  background: transparent;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: #64748b;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.agent-chevron {
  transition: transform 0.2s ease;
}

.agent-thoughts-card .agent-chevron {
  transform: rotate(180deg);
}

.agent-thoughts-card.collapsed .agent-chevron {
  transform: rotate(0deg);
}

.agent-thoughts-card.collapsed .agent-thoughts-body {
  display: none;
}

.agent-thoughts-card.collapsed .agent-thoughts-header {
  border-bottom: none;
}

.agent-thoughts-body {
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.74rem;
  line-height: 1.5;
  color: #334155;
  max-height: 240px;
  overflow-y: auto;
  background: #ffffff;
}

.thought-line {
  margin-bottom: 4px;
  word-break: break-word;
  white-space: pre-wrap;
}

.thought-muted {
  color: #94a3b8;
  font-style: italic;
}

.thought-exec {
  color: #2563eb;
}

.thought-success {
  color: #059669;
  font-weight: 500;
}

.thought-json {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 6px 8px;
  margin: 4px 0 6px 0;
  overflow-x: auto;
  font-size: 0.72rem;
  color: #0f172a;
  white-space: pre;
}

.thought-json code {
  font-family: inherit;
}

.bot-text-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.error-message {
  background: #fee2e2;
  color: #991b1b;
  align-self: center;
  font-size: 0.8rem;
  max-width: 95%;
  text-align: center;
}

/* Chat Visualization Cards */
.chat-chart-card {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
  width: 100%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  box-sizing: border-box;
}

.chat-chart-title {
  font-weight: 600;
  font-size: 0.82rem;
  color: #334155;
  margin-bottom: 6px;
  text-align: center;
}

.chat-chart-canvas {
  max-height: 220px !important;
  width: 100% !important;
}

/* Chat Input Bar */
.chat-input-area {
  padding: 10px;
  background: white;
  border: 1px solid #cbd5e1;
  border-top: 0;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
  display: flex;
  gap: 8px;
  flex: 0 0 auto !important;
  align-items: flex-end;
}

.chat-input-area textarea {
  flex: 1 1 auto !important;
  min-height: 76px !important;
  max-height: 160px !important;
  height: 76px;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: none;
  font-size: 0.88rem;
  line-height: 1.4;
  resize: vertical;
  overflow-y: auto;
  transition: border-color 0.2s;
  box-sizing: border-box !important;
}

.chat-input-area textarea:focus {
  border-color: #3b82f6;
}

.chat-input-area button {
  background: #3b82f6;
  color: white;
  border: none;
  padding: 0 14px;
  height: 38px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.88rem;
  transition: background 0.2s;
  flex: 0 0 auto !important;
}

.chat-input-area button:hover {
  background: #2563eb;
}

.chat-input-area button:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

/* Media Queries */
@media (min-width: 640px) {
  .geoai-geocode-status {
    flex: 1 1 auto;
    margin-left: 0.25rem;
  }
}

@media (min-width: 769px) {
  .geoai-header {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 60px !important;
    padding: 0 1rem !important;
  }

  .geoai-header .icimod-logo-wrap {
    position: absolute !important;
    left: 1rem !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
  }

  .geoai-header .icimod-mode-nav {
    position: absolute !important;
    right: 1rem !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
  }

  .geoai-page-title {
    margin: 0 !important;
    text-align: center !important;
  }
}

@media (max-width: 768px) {
  .geoai-header {
    flex-wrap: wrap !important;
    justify-content: center !important;
    row-gap: 0.4rem !important;
    height: auto !important;
  }

  .geoai-page-title {
    flex: 1 1 100% !important;
    order: 3 !important;
  }

  .geoai-header .icimod-mode-nav {
    order: 2 !important;
  }

  .geoai-columns {
    flex-direction: column !important;
    height: calc(100% - 100px) !important;
  }

  .geoai-map-column,
  .geoai-llm-column {
    flex: 1 1 50% !important;
    width: 100% !important;
    max-width: none !important;
  }

  .geoai-map-column {
    border-right: 0 !important;
    border-bottom: 1px solid #cbd5e1 !important;
  }

  .geoai-geocode-form {
    margin-left: 0;
    max-width: none;
  }
}

/* ——— District Map Pin Overlay & Badges ——— */
.geoai-district-overlay {
  pointer-events: none;
  z-index: 150;
  transform: translate(-50%, -100%);
  animation: geoaiPinPop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes geoaiPinPop {
  0% {
    opacity: 0;
    transform: translate(-50%, -80%) scale(0.8);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -100%) scale(1);
  }
}

.geoai-district-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  color: #ffffff;
  padding: 6px 12px;
  border-radius: 20px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.15);
  font-size: 0.82rem;
  white-space: nowrap;
  pointer-events: auto;
  cursor: default;
}

.geoai-badge-pin {
  font-size: 1rem;
  line-height: 1;
}

.geoai-badge-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.geoai-badge-name {
  color: #38bdf8;
  font-size: 0.85rem;
  font-weight: 600;
}

.geoai-badge-sub {
  color: #94a3b8;
  font-size: 0.72rem;
  font-weight: 400;
}

/* ——— Map Geocode Autocomplete Dropdown ——— */
.geoai-geocode-dropdown {
  border-radius: 8px !important;
  border: 1px solid #cbd5e1 !important;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.1) !important;
}

.geoai-dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.15s ease;
}

.geoai-dropdown-item:last-child {
  border-bottom: none;
}

.geoai-dropdown-item:hover {
  background: #f0f9ff;
}

.hkh-district-item .dropdown-item-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #0f172a;
}

.dropdown-item-sub {
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 2px;
}

.geoai-tag {
  background: #e0f2fe;
  color: #0369a1;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.osm-item .dropdown-item-title {
  font-size: 0.8rem;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ——— Chat Location Interactive Chip ——— */
.chat-location-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  padding: 4px 10px;
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
  border-radius: 14px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.chat-location-chip:hover {
  background: #0284c7;
  color: #ffffff;
  border-color: #0284c7;
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(2, 132, 199, 0.25);
}

