:root {
  --background: #ffffff;
  --foreground: #111111;
  --muted-foreground: #666666;
  --border: #eaeaea;
  --input-bg: #ffffff;
  --user-message-bg: #000000;
  --user-message-text: #ffffff;
  --model-message-bg: #f9f9f9;
  --model-message-border: #efefef;
  --button-bg: #4a4a4a;
  --button-text: #ffffff;
  --header-height: 56px;
  --footer-height: 90px;
  --font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.dark {
  --background: #000000;
  --foreground: #ffffff;
  --muted-foreground: #999999;
  --border: #333333;
  --input-bg: #111111;
  --user-message-bg: #ffffff;
  --user-message-text: #000000;
  --model-message-bg: #111111;
  --model-message-border: #333333;
  --button-bg: #f0f0f0;
  --button-text: #000000;
}

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

html,
body {
  height: 100%;
  font-family: var(--font-family);
  background-color: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  position: relative;
}

body::before, body::after {
    content: '';
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    z-index: -1;
    background-repeat: no-repeat;
    pointer-events: none;
    filter: blur(60px);
}

body::before { /* top gradient */
    top: -50px;
    width: 100%;
    height: 150px;
    background-image: radial-gradient(ellipse at top, rgba(0, 120, 255, 0.1), transparent 80%);
}

body::after { /* bottom gradient */
    bottom: -50px;
    width: 100%;
    height: 250px;
    background-image: radial-gradient(ellipse at bottom, rgba(0, 120, 255, 0.15), transparent 80%);
}

.view {
  display: flex;
  flex-direction: column;
  height: 100vh; /* Fallback for older browsers */
  height: 100dvh; /* Use dynamic viewport height */
  width: 100%;
  transition: opacity 0.3s ease;
}

/* Chat view should be 85% width */
#chat-view {
  width: 85%;
  max-width: 1200px;
  margin: 0 auto;
}

.hidden {
  display: none;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.5rem;
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  font-size: 1.5rem;
  font-weight: 200;
}

.app-header nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.header-link {
  background: none;
  border: none;
  color: var(--muted-foreground);
  text-decoration: none;
  font-size: 0.875rem;
  cursor: pointer;
  transition: color 0.2s ease;
}

.header-link:hover {
  color: var(--foreground);
}

.header-text {
  color: var(--muted-foreground);
  font-size: 0.875rem;
}

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
}

.theme-toggle svg {
  width: 100%;
  height: 100%;
}

.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }
.dark .theme-toggle .sun-icon { display: block; }
.dark .theme-toggle .moon-icon { display: none; }

/* Initial View */
.initial-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1rem;
}

.initial-content-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding-bottom: 15vh; /* Push content up slightly */
}

.brand-container {
  margin-bottom: 2rem;
}

.brand-name {
  font-size: clamp(4rem, 10vw + 2rem, 6rem);
  font-weight: 200;
  letter-spacing: -0.05em;
}

.brand-tagline {
  font-size: 1.25rem;
  color: var(--muted-foreground);
  margin-top: 0.5rem;
}

/* Chat View */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message {
  max-width: 90%;
  word-wrap: break-word; /* Fallback */
  overflow-wrap: break-word; /* Modern property */
  word-break: break-word; /* Break long words */
  line-height: 1.6;
}

/* Ensure generated code/preformatted text also wraps */
.message pre,
.message code {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}


.user-message {
  background-color: var(--user-message-bg);
  color: var(--user-message-text);
  align-self: flex-end;
  border-radius: 1.25rem;
  padding: 0.75rem 1.25rem;
  font-weight: 500;
}

.model-message {
  background-color: var(--model-message-bg);
  color: var(--foreground);
  align-self: flex-start;
  border-radius: 1.25rem;
  padding: 0.75rem 1.25rem;
  border: 1px solid var(--model-message-border);
}

.error-message {
   background-color: var(--model-message-bg);
   color: #ff4d4d;
   align-self: flex-start;
   border-radius: 1.25rem;
   padding: 0.75rem 1.25rem;
   border: 1px solid #ff4d4d;
   font-weight: 500;
}

.loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dot {
  width: 8px;
  height: 8px;
  background-color: var(--muted-foreground);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }


/* Table Styles */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* For smooth scrolling on iOS */
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.message table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
  border: none;
  border-radius: 0;
  min-width: 500px;
  table-layout: fixed;
}

.message th, .message td {
  padding: 0.75rem 1rem;
  text-align: left;
  overflow-wrap: break-word; /* Ensure text wraps in cells */
}
.message thead tr { background-color: var(--model-message-bg); border-bottom: 2px solid var(--border); }
.message th { font-weight: 600; }
.message tbody tr { border-bottom: 1px solid var(--border); }
.message tbody tr:last-of-type { border-bottom: 0; }
.dark .message tbody tr:nth-of-type(even) { background-color: rgba(255, 255, 255, 0.03); }
.dark .message tbody tr:nth-of-type(odd) { background-color: transparent; }

/* Table Sorting Styles */
.message th.sortable {
  cursor: pointer;
  position: relative;
  user-select: none;
}

.message th.sortable::after {
  content: ' \2195'; /* Up/down arrow */
  opacity: 0.4;
  position: absolute;
  right: 0.5rem;
  font-size: 0.8em;
}

.message th.sortable.sort-asc::after {
  content: ' \25B2'; /* Up triangle */
  opacity: 1;
}

.message th.sortable.sort-desc::after {
  content: ' \25BC'; /* Down triangle */
  opacity: 1;
}


/* Forms & Footer */
.chat-footer, .initial-chat-form {
  padding: 1rem 1.5rem;
  background-color: var(--background);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.initial-chat-form {
  border-top: none;
  width: 100%;
  max-width: 48rem;
}

.textarea-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  align-items: flex-end;
  background-color: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 1.5rem;
  padding: 0.5rem;
  padding-right: 3.5rem; /* Space for button */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.dark .textarea-wrapper {
   box-shadow: 0 4px 12px rgba(255, 255, 255, 0.05);
}

textarea {
  flex-grow: 1;
  width: 100%;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--foreground);
  font-family: var(--font-family);
  font-size: 1rem;
  line-height: 1.5;
  padding: 0.5rem;
  max-height: 200px;
  min-height: 44px;
  overflow-y: auto;
}

.initial-view textarea {
  min-height: 144px;
  padding-top: 1rem;
  font-size: 1.1rem;
}

textarea::placeholder {
  color: var(--muted-foreground);
}

.textarea-wrapper button {
  position: absolute;
  right: 0.5rem;
  bottom: 0.5rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  border: none;
  background-color: var(--button-bg);
  color: var(--button-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s;
}

.textarea-wrapper button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.footer-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.footer-action-btn, .footer-action-link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: none;
  color: var(--muted-foreground);
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.2s ease;
  text-decoration: none;
  font-family: var(--font-family);
}

.footer-action-btn:hover, .footer-action-link:hover {
  color: var(--foreground);
}

.footer-action-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
}

.launch-pricepilot-btn {
  margin-top: 1.5rem;
  padding: 0.65rem 1.25rem;
  background-color: var(--model-message-bg);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  color: var(--muted-foreground);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.launch-pricepilot-btn:hover {
  background-color: var(--border);
  color: var(--foreground);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

.dark .launch-pricepilot-btn {
  box-shadow: 0 2px 4px rgba(255, 255, 255, 0.05);
}

.dark .launch-pricepilot-btn:hover {
  background-color: var(--border);
}


.app-footer-text {
    text-align: center;
    font-size: 0.75rem;
    color: var(--muted-foreground);
}

.initial-view .app-footer-text {
    margin-top: auto;
    padding-bottom: 1rem;
}

.chat-footer .app-footer-text {
    margin-top: 1rem;
    padding-bottom: 0.5rem;
}


/* Responsive Design */
@media (max-width: 768px) {
  .brand-tagline {
    font-size: 1rem;
  }
  .app-header, .chat-footer, .initial-chat-form {
    padding: 0 1rem;
  }
  .chat-footer {
    padding-bottom: 1.5rem; /* Extra space for home bar */
  }
  #chat-container {
    padding: 1rem;
  }
  .footer-actions {
    gap: 1rem;
    justify-content: space-around;
  }
}