/* base.css - Base Styles and Reset */

#smartfence-embed-root * { 
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body,
#smartfence-embed-root { 
  height: 100%;
  overflow: hidden;
  position: relative;
}

/* EMBED MODE: Override fixed positioning for embed mode */
/* Use multiple selectors for maximum specificity */
body .sf-embed-mode html,
body .sf-embed-mode body,
body html.sf-embed-mode,
body body.sf-embed-mode,
.sf-embed-mode html,
.sf-embed-mode body,
html.sf-embed-mode,
body.sf-embed-mode { 
  height: auto !important;
  overflow: visible !important;
  position: static !important;
}

body,
#smartfence-embed-root { 
  font-family: var(--font-family);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.5; /* Updated from 1.6 to match estimator */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* FIXED: Mobile-safe app container with proper viewport handling */
#smartfence-embed-root .app-container { 
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Use dvh (dynamic viewport height) for better mobile support */
  height: 100dvh;
  max-height: 100dvh;
}

/* EMBED MODE: Override fixed positioning for embed mode */
/* Multiple selectors for maximum specificity */
body .sf-embed-mode .app-container,
body.sf-embed-mode .app-container,
#smartfence-chatbot .app-container,
[id*="chatbot"] .app-container,
.app-container[data-embed-mode="true"],
#smartfence-embed-root .sf-embed-mode .app-container { 
  position: relative !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

/* Fallback for browsers that don't support dvh */
@supports not (height: 100dvh) {
  #smartfence-embed-root .app-container { 
    height: 100vh;
    max-height: 100vh;
  }
  
  /* EMBED MODE: Override for embed mode */
  body .sf-embed-mode .app-container,
  #smartfence-chatbot .app-container,
  [id*="chatbot"] .app-container,
  #smartfence-embed-root .sf-embed-mode .app-container { 
    height: auto !important;
    max-height: none !important;
  }
}

/* Additional mobile viewport fixes */
@media (max-width: 768px) {
  #smartfence-embed-root .app-container { 
    /* Prevent overscroll on mobile */
    overscroll-behavior: none;
    /* Ensure input area doesn't get cut off */
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  #smartfence-embed-root html, #smartfence-embed-root body { 
    /* Prevent pull-to-refresh and overscroll */
    overscroll-behavior: none;
    position: fixed;
    width: 100%;
  }
  
  /* EMBED MODE: Override mobile fixes for embed mode */
  body .sf-embed-mode html,
  body .sf-embed-mode body,
  .sf-embed-mode html,
  #smartfence-embed-root .sf-embed-mode body { 
    position: static !important;
    width: auto !important;
    overflow: visible !important;
  }
  
  body .sf-embed-mode .app-container,
  #smartfence-chatbot .app-container,
  [id*="chatbot"] .app-container,
  #smartfence-embed-root .sf-embed-mode .app-container { 
    position: relative !important;
    overscroll-behavior: auto !important;
  }
}

/* Focus states for accessibility */
.btn:focus,
.option-card:focus,
.suggestion-card:focus,
.suggestion-chip:focus,
#smartfence-embed-root .quick-action:focus { 
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.btn:focus:not(:focus-visible),
.option-card:focus:not(:focus-visible),
.suggestion-card:focus:not(:focus-visible),
.suggestion-chip:focus:not(:focus-visible),
#smartfence-embed-root .quick-action:focus:not(:focus-visible) { 
  outline: none;
}

/* Scrollbar styling */
#smartfence-embed-root .chat-messages::-webkit-scrollbar { 
  width: 6px;
}

#smartfence-embed-root .chat-messages::-webkit-scrollbar-track { 
  background: var(--bg-tertiary);
  border-radius: 3px;
}

#smartfence-embed-root .chat-messages::-webkit-scrollbar-thumb { 
  background: var(--border-color);
  border-radius: 3px;
}

#smartfence-embed-root .chat-messages::-webkit-scrollbar-thumb:hover { 
  background: var(--text-light);
}

/* Firefox scrollbar */
#smartfence-embed-root .chat-messages { 
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) var(--bg-tertiary);
}

/* Print styles */
@media print {
  .app-header,
  .input-area,
  .quick-actions,
  .btn-voice,
  .suggestion-chip,
  #smartfence-embed-root .suggestion-card { 
    display: none !important;
  }

  #smartfence-embed-root .chat-messages { 
    overflow: visible !important;
    height: auto !important;
  }

  #smartfence-embed-root .message-content { 
    break-inside: avoid;
  }

  #smartfence-embed-root body,
  body { 
    background: white !important;
    color: black !important;
  }
}

/* Ensure header structure is correct */
#smartfence-embed-root .app-header { 
  padding: 0.75rem 1rem;
  flex-shrink: 0; /* Prevent header from shrinking */
}

#smartfence-embed-root .chat-controls { 
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 1rem;
}

#smartfence-embed-root .logo-container { 
  width: 100%;
}

/* Remove any conflicting styles that might be breaking the layout */
#smartfence-embed-root .header-buttons { 
  display: flex !important;
  align-items: center !important;
  gap: 0.5rem !important;
}

/* Discreet "Powered by SmartFence" footer - matches navigation.css styling */
#smartfence-embed-root .powered-by { 
  text-align: center;
  padding: 0.5rem 0 0 0;
  margin-bottom: -0.5rem; /* Pull up to reduce space below */
  flex-shrink: 0; /* Prevent footer from shrinking */
}

#smartfence-embed-root .powered-by span { 
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 400;
}

#smartfence-embed-root .powered-by strong { 
  color: var(--primary-color);
  font-weight: 600;
  font-size: 0.875rem;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  #smartfence-embed-root .powered-by span { 
    font-size: 0.8rem;
  }

  #smartfence-embed-root .powered-by { 
    padding: 0.375rem 0 0.125rem 0;
  }
}