* {
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "SF Pro Display", sans-serif;
}

body {
  margin: 0;
  background: #000;
  color: #fff;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* Header */
.header {
  background: #000;
  border-bottom: 1px solid #222;
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 500;
  color: #fff;
}

/* Chat container — full width, minimal safe padding */
#chat {
  flex: 1;
  padding: 1.25rem 1rem; /* 1rem = 16px safe area on mobile */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

#chat::-webkit-scrollbar {
  width: 3px;
}

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

#chat::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 1.5px;
}

/* Message wrapper — full width */
.msg-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-self: stretch;
}

/* Message bubble */
.msg {
  width: 100%;
  padding: 0.875rem 1rem;
  border-radius: 18px;
  line-height: 1.5;
  word-wrap: break-word;
  font-size: 0.95rem;
  background: #0a0a0a;
  color: #fff;
}

.msg.user {
  background: #111;
}

/* Timestamp */
.timestamp {
  font-size: 0.7rem;
  color: #888;
  margin-top: 0.25rem;
  opacity: 0.9;
  text-align: right;
}

.msg-wrapper.bot .timestamp {
  text-align: left;
}

/* Copy button — aligned to safe area */
.copy-btn {
  position: absolute;
  top: -20px;
  background: #333;
  border: 1px solid #444;
  color: #fff;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-size: 0.7rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
  font-weight: 500;
  z-index: 10;
}

.msg-wrapper.bot .copy-btn {
  left: 1rem; /* match #chat padding */
}

.msg-wrapper.user .copy-btn {
  right: 1rem;
}

.msg-wrapper:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: #444;
  border-color: #555;
}

/* Markdown — optimized for wide layout */
.msg h1, .msg h2, .msg h3, .msg h4, .msg h5, .msg h6 {
  margin: 0.5rem 0;
  font-weight: 600;
}

.msg p {
  margin: 0.5rem 0;
}

.msg ul, .msg ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem; /* reduced for wide layout */
}

.msg li {
  margin: 0.2rem 0;
  padding-left: 0.1rem;
}

.msg blockquote {
  margin: 0.5rem 0;
  padding-left: 1rem;
  border-left: 3px solid #444;
  color: #ccc;
}

.msg strong {
  font-weight: 600;
}

.msg em {
  font-style: italic;
}

.msg code {
  background: #222;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-size: 0.85em;
  border: 1px solid #333;
}

.msg pre {
  background: #111;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 1rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  position: relative;
}

.msg pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: 0.9em;
}

/* Code copy button */
.code-block-wrapper {
  position: relative;
}

.code-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: #333;
  border: 1px solid #444;
  color: #fff;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.code-copy-btn:hover {
  opacity: 1;
  background: #444;
}

/* Typing indicator */
.typing {
  width: 100%;
  background: #111;
  border-radius: 18px;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.typing-dots {
  display: flex;
  gap: 0.25rem;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: #888;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

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

@keyframes typingBounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Input form */
#form {
  display: flex;
  background: #000;
  border-top: 1px solid #222;
  padding: 1rem;
  gap: 0.75rem;
  position: sticky;
  bottom: 0;
  align-items: flex-end;
}

#input {
  flex: 1;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  background: #111;
  color: #fff;
  outline: none;
  transition: border-color 0.2s ease;
  resize: none;
  min-height: 44px;
  max-height: 150px;
  overflow-y: auto;
  line-height: 1.4;
}

#input:focus {
  border-color: #555;
}

#input::placeholder {
  color: #777;
}

#input::-webkit-scrollbar {
  width: 3px;
}

#input::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 1.5px;
}

#send {
  background: #1e1e1e;
  border: 1px solid #444;
  color: #fff;
  padding: 0.875rem 1.25rem;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
  min-width: 70px;
  height: 44px;
}

#send:hover:not(:disabled) {
  background: #222;
}

#send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#loginBtn {
  background: #000;
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  cursor: pointer;
}

/* Rating panel */
#ratingPanel {
  padding: 1rem;
  background: #111;
  border-radius: 12px;
  margin: 0 1rem 1rem;
  font-size: 0.9rem;
}

#ratingPanel label {
  display: block;
  margin-bottom: 0.5rem;
}

#ratingPanel input[type="range"] {
  width: 100%;
  margin: 0.25rem 0;
}

#btnRate {
  margin-top: 8px;
  background: #1e1e1e;
  color: #fff;
  border: 1px solid #444;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
}

#btnRate:hover {
  background: #222;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .header {
    padding: 0.5rem 1rem;
  }

  .header h1 {
    font-size: 1rem;
  }

  #chat {
    padding: 1rem 1rem;
    gap: 1rem;
  }

  .msg {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
  }

  #form {
    padding: 0.75rem;
    gap: 0.5rem;
  }

  #input {
    font-size: 16px;
    padding: 0.75rem;
  }

  #send {
    padding: 0.75rem 1rem;
    min-width: 60px;
  }
}
