:root {
  --sidebar-width: 260px;
  --sidebar-bg: var(--ink);
  --sidebar-text: #fff;
  --chat-bg: #fff;
  --user-msg-bg: #f4f4f4;
  --assistant-msg-bg: transparent;
  --input-area-bg: #fff;
  --border-color: #e5e5e5;
}

body, html {
  height: 100%;
  margin: 0;
  overflow: hidden; /* Prevent body scroll, handle in containers */
}

.chat-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  background-color: var(--chat-bg);
  font-family: var(--font-body);
}

/* Sidebar */
.chat-sidebar {
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.sidebar-header {
  margin-bottom: 1.5rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 1rem;
  transition: color 0.2s;
}

.back-link:hover {
  color: #fff;
}

.sidebar-logo {
  max-width: 140px;
  filter: brightness(0) invert(1); /* Make logo white */
  opacity: 0.9;
}

.new-chat-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 0.5rem;
  padding: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
  font-size: 0.9rem;
  text-align: left;
}

.new-chat-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.new-chat-btn::before {
  content: '+';
  font-size: 1.2rem;
  font-weight: 300;
}

.sidebar-spacer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-history {
  margin-top: 1.5rem;
  overflow-y: auto;
  padding-right: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.chat-history__item {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  color: rgba(255, 255, 255, 0.85);
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.chat-history__item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.chat-history__item.is-active {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.4);
}

.chat-history__empty {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
  padding: 0.5rem 0;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 1rem;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-footer a {
  color: inherit;
  text-decoration: none;
}

.sidebar-footer a:hover {
  text-decoration: underline;
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100%;
  background: var(--chat-bg);
}

.chat-header-mobile {
  display: none;
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  align-items: center;
  justify-content: space-between;
}

/* Chat Log */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: clamp(1.25rem, 4vw, 2rem);
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

/* Messages */
.chat-message {
  width: 100%;
  max-width: 800px; /* ChatGPT width constraint */
  padding: clamp(1rem, 3vw, 1.5rem) 1rem;
  display: flex;
  gap: clamp(0.85rem, 2.5vw, 1.5rem);
  line-height: 1.6;
  font-size: 1rem;
  color: var(--ink);
  border-bottom: 1px solid transparent; /* Spacing consistency */
  
  /* Resets from main.css */
  background: transparent;
  box-shadow: none;
  border: none;
  border-radius: 0;
  margin: 0;
}

.chat-message--user {
  background: transparent;
}

.chat-message--assistant {
  background: transparent;
  color: var(--ink);
}

.chat-message__avatar {
  width: 36px;
  height: 36px;
  border-radius: 4px; /* ChatGPT has slightly rounded squares for avatars usually, or circles */
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: #fff;
}

.chat-message--user .chat-message__avatar {
  background-color: #5c6b89; /* User placeholder color */
  border-radius: 50%;
}

.chat-message--assistant .chat-message__avatar {
  background-color: var(--accent); /* Adapt AI Blue */
  border-radius: 4px;
}

.chat-message__content {
  flex: 1;
  min-width: 0;
}

.chat-message__role {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
  color: var(--ink);
}

.chat-message__text {
  white-space: pre-wrap;
}

/* Attachments styling within message */
.chat-message__attachments {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.attachment-pill {
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  background: rgba(0,0,0,0.05);
  border: 1px solid rgba(0,0,0,0.1);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

/* Input Area */
.input-container {
  width: 100%;
  padding: 1rem 2rem calc(2rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, #fff 20%);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
}

.chat-form {
  width: min(100%, 800px);
  position: relative;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  box-shadow: 0 0 10px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  gap: 0.25rem;
}

.chat-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 15px rgba(60, 103, 255, 0.15);
}

.input-files-preview {
  padding: 0.5rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.input-files-preview[hidden] {
  display: none;
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
  width: 100%;
}

.file-attach-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.2s;
}

.file-attach-btn:hover {
  background-color: rgba(0,0,0,0.05);
  color: var(--ink);
}

.file-attach-btn input {
  display: none;
}

.chat-textarea {
  flex: 1;
  border: none;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  min-width: 0;
  padding: 0.5rem 0;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  outline: none;
}

.send-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  background-color: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s;
}

.send-btn:disabled {
  background-color: #e5e5e5;
  color: #aaa;
  cursor: not-allowed;
}

.send-btn svg {
  width: 16px;
  height: 16px;
}

.input-helper-text {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.footer-text {
  text-align: left;
  font-size: 0.75rem;
  color: #aaa;
  width: min(100%, 800px);
}

@media (max-width: 600px) {
  .chat-container {
    padding: 1rem;
  }

  .chat-message {
    padding: 1rem 0.5rem;
    gap: 0.75rem;
  }

  .chat-message__avatar {
    width: 32px;
    height: 32px;
  }

  .chat-input-row {
    gap: 0.5rem;
  }

  .input-container {
    padding: 0.75rem 1rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
  }

  .chat-form,
  .footer-text {
    width: 100%;
  }
}

/* Hero/Welcome State */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 2rem;
  margin-top: -4rem; /* visual offset */
}

.welcome-logo {
  width: 80px;
  height: 80px;
  background: #fff;
  border-radius: 50%;
  padding: 1rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1);
  margin-bottom: 1.5rem;
}

.welcome-title {
  font-size: 1.75rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.welcome-subtitle {
  color: var(--muted);
}

/* Responsive */
@media (max-width: 768px) {
  .chat-sidebar {
    display: none; /* Hidden by default on mobile for now, or use a toggle */
  }
  
  .chat-layout {
    flex-direction: column;
  }
  
  .chat-header-mobile {
    display: flex;
  }
}
