/* Reset box-sizing for everything */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Base styles */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial,
    sans-serif;
  min-height: 95vh;
  margin: 0;
  padding: 0;
  background-color: #fff;
  color: #222;
  box-sizing: border-box;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Container: centered app look */
.container {
  background: #fff;
  border-radius: 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  max-width: auto;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* When running inside Tableau (iframe), use all available space */
body.in-extension .container {
  max-width: 100vw !important;
  width: 100vw !important;
  margin: 0 !important;
  border-radius: 0;
  height: 100vh;
  min-height: 0;
}

/* Chat box should flex and scroll as needed */
.chat-box {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  background: #f8fafc;
  min-height: 0;
}

/* Header styles */
header {
  background: #466585;
  color: #fff;
  padding: 15px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  min-height: 80px;
}

.header-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}

header h1 {
  margin: 0;
  font-size: 2em;
}

.branding {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 4px;
}

.branding-logo {
  width: 16px;
  height: 16px;
  opacity: 0.8;
}

.branding-text {
  font-size: 0.7em;
  opacity: 0.7;
  font-weight: 400;
  font-style: italic;
}

header p {
  margin: 0;
  opacity: 0.9;
}

#resetBtn {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 8px 12px;
  background: #6c757d;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 20px;
  font-weight: 500;
  transition: background-color 0.2s;
  line-height: 1;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#resetBtn:hover {
  background: #5a6268;
}

#resetBtn:disabled {
  background: #dee2e6;
  cursor: not-allowed;
}

/* Datasource selector styles */
.datasource-selector {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  order: -1;
}

.datasource-selector label {
  font-weight: 500;
  color: #fff;
  margin-bottom: 0;
  order: 1;
}

.status-indicator {
  order: 0;
}

#datasourceSelect {
  padding: 5px 10px;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 14px;
  min-width: 200px;
  width: 100%;
  order: 2;
}

#datasourceSelect:hover {
  border-color: #357ae8;
}

.status-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #28a745;
  animation: pulse 2s infinite;
}

.status-indicator.loading {
  background: #ffc107;
  animation: spin 1s linear infinite;
}

.status-indicator.error {
  background: #dc3545;
  animation: none;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Chat message styles */
.message {
  margin: 15px 0;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 80%;
  line-height: 1.3;
}

.message.user {
  background: #357ae8;
  color: #fff;
  margin-left: auto;
  text-align: right;
}

.message.bot {
  background: #e9ecef;
  color: #222;
}

/* Input area at the bottom */
.input-area {
  display: flex;
  gap: 10px;
  padding: 10px;
  background: #fff;
  border-top: 1px solid #dee2e6;
}

#messageInput {
  flex: 1;
  padding: 6px 8px;
  border: 2px solid #dee2e6;
  border-radius: 6px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

#messageInput:focus {
  border-color: #357ae8;
}

#sendBtn {
  padding: 6px 12px;
  background: #357ae8;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.2s;
}

#sendBtn:hover {
  background: #2456a5;
}

#sendBtn:disabled {
  background: #dee2e6;
  cursor: not-allowed;
}

/* Responsive for smaller screens */
@media (max-width: 768px) {
  header {
    flex-direction: column;
    align-items: center;
    gap: 5px;
  }
  
  .header-title {
    position: static;
    transform: none;
    width: 100%;
    order: 0;
  }
  
  header h1 {
    font-size: 1.8em;
    width: 100%;
    text-align: center;
  }
  
  .datasource-selector {
    width: 100%;
    margin-top: 0;
    order: 1;
  }
  
  #datasourceSelect {
    width: calc(100% - 20px);
  }
  
  #resetBtn {
    top: 10px;
    right: 10px;
  }
  
  .chat-box {
    padding: 15px;
  }
  
  .input-area {
    padding: 15px;
  }
}

/* Markdown-specific styles */
.message.bot table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 14px;
  background: white;
  border-radius: 4px;
  overflow: hidden;
}

.message.bot thead {
  background: #f1f3f5;
}

.message.bot th,
.message.bot td {
  padding: 8px 12px;
  text-align: left;
  border: 1px solid #dee2e6;
}

.message.bot th {
  font-weight: 600;
  color: #495057;
}

.message.bot tr:nth-child(even) {
  background: #f8f9fa;
}

.message.bot code {
  background: #f1f3f5;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
  color: #e83e8c;
}

.message.bot pre {
  background: #f8f9fa;
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  border-left: 3px solid #357ae8;
  margin: 10px 0;
}

.message.bot pre code {
  background: transparent;
  padding: 0;
  color: #212529;
}

.message.bot strong {
  font-weight: 600;
  color: #212529;
}

.message.bot em {
  font-style: italic;
}

.message.bot h1,
.message.bot h2,
.message.bot h3,
.message.bot h4 {
  margin: 12px 0 8px 0;
  font-weight: 600;
  line-height: 1.3;
  color: #212529;
}

.message.bot h1 { font-size: 1.5em; }
.message.bot h2 { font-size: 1.3em; }
.message.bot h3 { font-size: 1.15em; }
.message.bot h4 { font-size: 1em; }

.message.bot ul,
.message.bot ol {
  margin: 8px 0;
  padding-left: 24px;
}

.message.bot li {
  margin: 4px 0;
}

.message.bot blockquote {
  border-left: 3px solid #dee2e6;
  padding-left: 12px;
  margin: 10px 0;
  color: #6c757d;
  font-style: italic;
}

.message.bot p {
  margin: 8px 0;
}

.message.bot a {
  color: #357ae8;
  text-decoration: none;
}

.message.bot a:hover {
  text-decoration: underline;
}
