/* Atlas Construct Chat Widget Styles */

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

:root {
  --primary: #262525;
  --secondary: #bf5050;
  --tertiary: #ffffff;
  --bg-color: #1a1919;
  --surface-color: #262525;
  --border-color: #3a3838;
  --text-color: #ffffff;
  --text-muted: #a0a0a0;
  --accent-color: #bf5050;
  --accent-hover: #a84444;
  --bot-bg: #312f2f;
  --user-bg: #bf5050;
  --input-bg: #1e1d1d;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

#chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 100%;
  position: relative;
}

/* Header */
#chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  min-height: 52px;
}

.header-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-status {
  font-size: 11px;
  font-weight: 500;
  color: #4ade80;
  background: rgba(74, 222, 128, 0.12);
  padding: 3px 10px;
  border-radius: 12px;
  flex-shrink: 0;
  margin-left: 12px;
}

.header-status.offline {
  color: #f87171;
  background: rgba(248, 113, 113, 0.12);
}

.header-status.thinking {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  animation: pulse-status 1.5s ease-in-out infinite;
}

.header-status.rate-limited {
  color: #f87171;
  background: rgba(248, 113, 113, 0.12);
}

@keyframes pulse-status {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Messages Area */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.message {
  display: flex;
  max-width: 85%;
  animation: messageIn 0.2s ease-out;
}

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

.message.user {
  align-self: flex-end;
}

.message.bot {
  align-self: flex-start;
}

.message-content {
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.5;
  font-size: 14px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

.message.user .message-content {
  background: var(--user-bg);
  color: var(--tertiary);
  border-bottom-right-radius: 4px;
}

.message.bot .message-content {
  background: var(--bot-bg);
  color: var(--text-color);
  border-bottom-left-radius: 4px;
}

/* Timestamp */
.message-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.message.user .message-time {
  text-align: right;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 12px 16px;
  align-items: center;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Input Area */
#chat-input-area {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface-color);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  align-items: flex-end;
}

#chat-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border-color);
  border-radius: 22px;
  background: var(--input-bg);
  color: var(--text-color);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  min-height: 42px;
  max-height: 42px;
  line-height: 1.4;
  resize: none;
  font-family: inherit;
}

#chat-input:focus {
  border-color: var(--accent-color);
}

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

#send-button {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--accent-color);
  color: var(--tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}

#send-button:hover {
  background: var(--accent-hover);
}

#send-button:active {
  transform: scale(0.93);
}

#send-button:disabled {
  background: var(--border-color);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Rate limit warning */
#rate-limit-notice {
  display: none;
  text-align: center;
  font-size: 12px;
  color: var(--secondary);
  padding: 6px 16px;
  background: rgba(191, 80, 80, 0.1);
  border-top: 1px solid rgba(191, 80, 80, 0.2);
  flex-shrink: 0;
}

#rate-limit-notice.visible {
  display: block;
}

/* Scrollbar */
#chat-messages::-webkit-scrollbar {
  width: 5px;
}

#chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

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

#chat-messages::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Error state */
.error-message {
  background: rgba(191, 80, 80, 0.12);
  border: 1px solid rgba(191, 80, 80, 0.3);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  text-align: center;
  animation: messageIn 0.2s ease-out;
}

/* Welcome message styling */
.welcome-message .message-content {
  background: var(--bot-bg);
  border-left: 3px solid var(--secondary);
}

/* Powered by footer */
#powered-by {
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  padding: 4px;
  background: var(--surface-color);
  opacity: 0.6;
  flex-shrink: 0;
}

#powered-by a {
  color: var(--text-muted);
  text-decoration: none;
}

#powered-by a:hover {
  color: var(--secondary);
}

/* ==========================================
   RESPONSIVE - Tablet
   ========================================== */
@media (max-width: 768px) {
  #chat-header {
    padding: 12px 16px;
  }

  #chat-messages {
    padding: 12px;
    gap: 10px;
  }

  .message {
    max-width: 90%;
  }

  .message-content {
    font-size: 14px;
    padding: 10px 12px;
  }

  #chat-input-area {
    padding: 10px 12px;
    gap: 8px;
  }
}

/* ==========================================
   RESPONSIVE - Mobile
   ========================================== */
@media (max-width: 480px) {
  #chat-header {
    padding: 10px 14px;
    min-height: 46px;
  }

  .header-title {
    font-size: 14px;
  }

  .header-status {
    font-size: 10px;
    padding: 2px 8px;
  }

  #chat-messages {
    padding: 10px;
    gap: 8px;
  }

  .message {
    max-width: 92%;
  }

  .message-content {
    font-size: 15px;
    padding: 9px 12px;
    border-radius: 14px;
  }

  .message.user .message-content {
    border-bottom-right-radius: 4px;
  }

  .message.bot .message-content {
    border-bottom-left-radius: 4px;
  }

  #chat-input-area {
    padding: 8px 10px;
    gap: 8px;
  }

  #chat-input {
    padding: 10px 14px;
    font-size: 16px; /* Prevents iOS zoom on focus */
    min-height: 40px;
    max-height: 40px;
    border-radius: 20px;
  }

  #send-button {
    width: 40px;
    height: 40px;
  }
}

/* ==========================================
   RESPONSIVE - Very small screens
   ========================================== */
@media (max-width: 360px) {
  .header-title {
    font-size: 13px;
  }

  .message-content {
    font-size: 14px;
    padding: 8px 10px;
  }

  #chat-input {
    padding: 8px 12px;
  }
}

/* ==========================================
   iOS Safe Area support
   ========================================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #chat-input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  #powered-by {
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
  }
}

/* ==========================================
   Landscape mobile
   ========================================== */
@media (max-height: 500px) and (orientation: landscape) {
  #chat-header {
    padding: 8px 14px;
    min-height: 40px;
  }

  .header-title {
    font-size: 13px;
  }

  #chat-messages {
    padding: 8px 12px;
    gap: 6px;
  }

  .message-content {
    padding: 8px 10px;
    font-size: 13px;
  }

  #chat-input-area {
    padding: 6px 10px;
  }

  #chat-input {
    min-height: 36px;
    max-height: 36px;
    padding: 8px 12px;
  }

  #send-button {
    width: 36px;
    height: 36px;
  }

  #powered-by {
    display: none;
  }
}
