/* ===================================================
   Maps Grounding — Global Styles
   =================================================== */

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

:root {
  --bg-base:       #f8f9fa;
  --bg-surface:    #ffffff;
  --bg-elevated:   #f1f3f5;
  --bg-hover:      #e9ecef;
  --border:        rgba(0,0,0,0.08);
  --border-bright: rgba(0,0,0,0.14);

  --accent:        #3b82f6;
  --accent-glow:   rgba(59,130,246,0.25);
  --accent-2:      #8b5cf6;
  --accent-grad:   linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);

  --text-primary:  #1e293b;
  --text-secondary:#475569;
  --text-muted:    #64748b;

  --pin-color:     #f97316;
  --pin-glow:      rgba(249,115,22,0.4);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --font-ui:   'Rubik', sans-serif;
  --font-brand:'Rubik', sans-serif;

  --topbar-h: 58px;
  --chat-w:   400px;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.4);
  --shadow-md: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-lg: 0 16px 64px rgba(0,0,0,0.6);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ===================================================
   Top Bar
   =================================================== */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.brand-icon svg {
  width: 18px;
  height: 18px;
}

.brand-name {
  font-family: var(--font-brand);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent);
}

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

.btn-ghost {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-ghost:hover {
  background: var(--bg-elevated);
  border-color: var(--border-bright);
  color: var(--text-primary);
}

/* ===================================================
   Layout
   =================================================== */

.layout {
  display: flex;
  height: 100vh;
  padding-top: var(--topbar-h);
}

/* ===================================================
   Map
   =================================================== */

.map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}
/* Floating controls on map */
.map-floating-btn {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.map-floating-btn:hover {
  background: white;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: rgba(0, 0, 0, 0.2);
}

/* Map Legend */
.map-legend {
  position: absolute;
  bottom: 24px;
  left: 24px;
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  min-width: 200px;
  max-width: 280px;
  box-shadow: var(--shadow-md);
  animation: fadeUp 0.3s ease;
  z-index: 10;
}

.legend-header {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.legend-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pin-color);
  box-shadow: 0 0 6px var(--pin-glow);
  flex-shrink: 0;
}

/* ===================================================
   Chat Panel
   =================================================== */

.chat-panel {
  width: var(--chat-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

/* Chat Header */
.chat-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-surface) 100%);
}

.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(79,142,247,0.1);
  border: 1px solid rgba(79,142,247,0.25);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
}

.ai-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

.chat-title {
  font-family: var(--font-brand);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 3px;
}

.chat-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-bright);
  border-radius: 4px;
}

/* Messages */
.message {
  display: flex;
  gap: 10px;
  animation: fadeUp 0.3s ease;
}

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

.message-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-ai .message-avatar {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 0 14px var(--accent-glow);
}

.message-user .message-avatar {
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  color: var(--text-secondary);
}

.message-user {
  flex-direction: row-reverse;
}

.message-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 85%;
}

.message-ai .message-content {
  align-items: flex-start;
}

.message-user .message-content {
  align-items: flex-end;
}

.message-content p {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.message-user .message-content p {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  border-color: rgba(59,130,246,0.3);
  color: #ffffff;
}

.message-content p:last-of-type {
  border-radius: 14px;
}

.message-ai .message-content p:first-of-type {
  border-top-left-radius: 4px;
}

.message-user .message-content p:first-of-type {
  border-top-right-radius: 4px;
}

/* Location Pills inside AI messages */
.location-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.location-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(249,115,22,0.1);
  border: 1px solid rgba(249,115,22,0.3);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.75rem;
  color: #fb923c;
  cursor: pointer;
  transition: all 0.2s ease;
}

.location-pill:hover {
  background: rgba(249,115,22,0.2);
  border-color: rgba(249,115,22,0.6);
  transform: translateY(-1px);
}

.location-pill-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #f97316;
}

/* Suggestion Chips */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chip {
  background: var(--bg-hover);
  border: 1px solid var(--border-bright);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-ui);
}

.chip:hover {
  background: var(--accent-glow);
  border-color: rgba(79,142,247,0.4);
  color: var(--accent);
  transform: translateY(-1px);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 16px 8px;
}

.ai-small {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 10px var(--accent-glow);
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  border-top-left-radius: 4px;
  padding: 10px 14px;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s ease-in-out infinite;
}

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ===================================================
   Chat Input
   =================================================== */

.chat-input-area {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-wrapper:focus-within {
  border-color: rgba(79,142,247,0.5);
  box-shadow: 0 0 0 3px rgba(79,142,247,0.08);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--text-primary);
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-input::-webkit-scrollbar {
  width: 3px;
}
.chat-input::-webkit-scrollbar-thumb {
  background: var(--border-bright);
  border-radius: 3px;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--accent-grad);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  box-shadow: 0 0 16px var(--accent-glow);
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.send-btn:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: 0 0 24px var(--accent-glow);
}

.input-hint {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 8px;
  letter-spacing: 0.02em;
}

/* ===================================================
   Custom Map Marker
   =================================================== */

.custom-marker {
  width: 36px;
  height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--accent-grad);
  box-shadow: 0 0 0 3px rgba(79,142,247,0.3), 0 4px 16px rgba(0,0,0,0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: markerDrop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.custom-marker:hover {
  box-shadow: 0 0 0 5px rgba(79,142,247,0.4), 0 6px 24px rgba(0,0,0,0.5);
}

@keyframes markerDrop {
  from { opacity: 0; transform: rotate(-45deg) translateY(-20px) scale(0.5); }
  to   { opacity: 1; transform: rotate(-45deg) translateY(0) scale(1); }
}

.custom-marker-inner {
  transform: rotate(45deg);
  color: #fff;
  font-size: 14px;
}

/* Info Window override */
.gm-style .gm-style-iw-c {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border-bright) !important;
  border-radius: var(--radius-md) !important;
  padding: 0 !important;
  box-shadow: var(--shadow-md) !important;
}

.gm-style .gm-style-iw-d {
  overflow: hidden !important;
}

.gm-style .gm-style-iw-t::after {
  background: var(--bg-elevated) !important;
  box-shadow: none !important;
}

.gm-style button.gm-ui-hover-effect {
  top: 6px !important;
  right: 6px !important;
}

.gm-style button.gm-ui-hover-effect span {
  background-color: var(--text-muted) !important;
}

.info-window {
  padding: 14px 16px;
  min-width: 180px;
  max-width: 240px;
}

.info-window-title {
  font-family: var(--font-brand);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.info-window-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.info-window-type {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(79,142,247,0.1);
  border: 1px solid rgba(79,142,247,0.2);
  border-radius: 4px;
  padding: 2px 6px;
}

/* ===================================================
   Map Style Overrides
   =================================================== */

/* Error state */
.map-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.map-error-icon {
  font-size: 2.5rem;
}

/* ===================================================
   Key Setup Modal
   =================================================== */

.key-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.key-modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-xl);
  padding: 40px 36px;
  max-width: 480px;
  width: calc(100% - 40px);
  box-shadow: var(--shadow-lg), 0 0 60px rgba(79,142,247,0.12);
  animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.key-modal-icon {
  font-size: 2.8rem;
  margin-bottom: 14px;
}

.key-modal-title {
  font-family: var(--font-brand);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

.key-modal-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 20px;
}

.key-modal-desc strong {
  color: var(--text-primary);
}

.key-modal-desc a {
  color: var(--accent);
  text-decoration: none;
}

.key-modal-desc a:hover {
  text-decoration: underline;
}

.key-modal-input-wrap {
  margin-bottom: 10px;
}

.key-modal-input {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  text-align: left;
}

.key-modal-input:focus {
  border-color: rgba(79,142,247,0.6);
  box-shadow: 0 0 0 3px rgba(79,142,247,0.1);
}

.key-modal-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 22px;
  line-height: 1.5;
}

.key-modal-btn {
  width: 100%;
  padding: 13px 20px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent-grad);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.key-modal-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px var(--accent-glow);
}

.key-modal-btn:active {
  transform: translateY(0);
}

.key-modal-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Reset key button in topbar */
.btn-key-reset {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  font-family: var(--font-ui);
  padding: 0;
}
.btn-key-reset:hover {
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  :root {
    --chat-w: 100%;
  }
  .layout {
    flex-direction: column;
  }
  .map-container {
    height: 45vh;
  }
  .chat-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    height: calc(55vh - var(--topbar-h));
  }
}
