/* Pi Chat Styles */
:root {
  --pi-purple: #7B3FE4;
  --pi-purple-dark: #6429CC;
  --pi-purple-light: #9D6BF0;
  --bg-primary: #FFFFFF;
  --bg-secondary: #F5F5F7;
  --bg-tertiary: #E5E5EA;
  --text-primary: #000000;
  --text-secondary: #6E6E73;
  --border: #D1D1D6;
  --success: #34C759;
  --danger: #FF3B30;
  --bot-color: #7B3FE4;
  --user-color: #007AFF;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.5;
}

/* Screens */
.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: flex;
}

/* Login Screen */
#login-screen {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, var(--pi-purple) 0%, var(--pi-purple-dark) 100%);
}

.login-container {
  text-align: center;
  background: white;
  padding: 3rem 2rem;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  max-width: 400px;
  width: 90%;
}

.pi-logo {
  width: 80px;
  height: 80px;
  margin-bottom: 1rem;
}

.login-container h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.info-text {
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.info-warning {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--danger);
  font-weight: 600;
}

/* Auth Mode Toggle */
.auth-mode-toggle {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: 10px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
}

.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.toggle-text {
  color: var(--text-secondary);
}

/* Sidebar Footer */
.sidebar-footer {
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.mode-banner {
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.mode-banner.test {
  background: #FFF3CD;
  color: #856404;
}

.mode-banner.pi {
  background: #D4EDDA;
  color: #155724;
}

.mode-icon {
  font-size: 1rem;
}

.mode-text {
  flex: 1;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
}

.btn-primary {
  background: var(--pi-purple);
  color: white;
}

.btn-primary:hover {
  background: var(--pi-purple-dark);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(123, 63, 228, 0.4);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  width: 100%;
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-icon {
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: var(--bg-tertiary);
}

/* Chat Layout */
.chat-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 320px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h2 {
  font-size: 1.5rem;
  color: var(--pi-purple);
}

.user-profile {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 1rem;
  align-items: center;
}

.user-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pi-purple), var(--pi-purple-light));
  flex-shrink: 0;
}

.user-info {
  flex: 1;
}

.user-name {
  font-weight: 600;
  font-size: 1rem;
}

.user-status {
  font-size: 0.875rem;
}

/* Auth mode indicator */
.auth-mode {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.auth-mode.pi {
  background: var(--pi-purple);
  color: white;
}

.auth-mode.test {
  background: #FF9500;
  color: white;
}

#create-room-btn {
  margin: 1rem 1.5rem 0.5rem;
}

.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.room-item {
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.room-item:hover {
  background: var(--bg-secondary);
}

.room-item.active {
  background: var(--pi-purple);
  color: white;
}

.room-item-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.room-item-last-message {
  font-size: 0.875rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-item.active .room-item-last-message {
  color: rgba(255, 255, 255, 0.8);
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
}

.no-room {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: var(--text-secondary);
  padding: 2rem;
}

.no-room svg {
  margin-bottom: 1rem;
  opacity: 0.5;
}

.no-room h3 {
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.chat-header {
  padding: 1rem 1.5rem;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.room-info {
  flex: 1;
}

.room-info h3 {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}

.room-info p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message {
  display: flex;
  gap: 0.75rem;
  max-width: 70%;
  animation: messageSlide 0.3s ease-out;
}

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

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

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  color: white;
}

.message.bot-message .message-avatar {
  background: linear-gradient(135deg, var(--bot-color), var(--pi-purple-light));
}

.message.user-message .message-avatar {
  background: linear-gradient(135deg, var(--user-color), #5AC8FA);
}

.message-content {
  flex: 1;
}

.message-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.message-sender {
  font-weight: 600;
  font-size: 0.875rem;
}

.message-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.message-bubble {
  padding: 0.75rem 1rem;
  border-radius: 16px;
  word-wrap: break-word;
}

.message.bot-message .message-bubble {
  background: var(--bg-primary);
  border: 1px solid var(--border);
}

.message.user-message .message-bubble {
  background: var(--user-color);
  color: white;
}

.typing-indicator {
  padding: 1rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-style: italic;
}

.message-input-container {
  padding: 1rem 1.5rem;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

#message-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  background: var(--bg-secondary);
}

#message-input:focus {
  outline: none;
  border-color: var(--pi-purple);
}

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--pi-purple);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-send:hover {
  background: var(--pi-purple-dark);
  transform: scale(1.1);
}

.btn-send:disabled {
  background: var(--border);
  cursor: not-allowed;
  transform: none;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 16px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.25rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--bg-secondary);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.form-group input[type="text"],
.form-group textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

.form-group input[type="text"]:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--pi-purple);
}

.form-group input[type="checkbox"] {
  margin-right: 0.5rem;
}

/* Search Results */
.search-results {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 0.5rem;
}

.search-placeholder {
  padding: 2rem;
  text-align: center;
  color: var(--text-secondary);
}

.search-result-item {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--bg-secondary);
}

.search-result-item.invited {
  background: var(--bg-secondary);
  opacity: 0.7;
}

.search-result-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pi-purple), var(--pi-purple-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  margin-right: 0.75rem;
  flex-shrink: 0;
}

.search-result-info {
  flex: 1;
}

.search-result-name {
  font-weight: 600;
}

.search-result-status {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.btn-invite {
  padding: 0.5rem 1rem;
  background: var(--pi-purple);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-invite:hover {
  background: var(--pi-purple-dark);
}

.btn-invite:disabled {
  background: var(--border);
  cursor: not-allowed;
}

/* Loading */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
}

/* Back button - hidden on desktop */
.back-btn {
  display: none;
  margin-right: 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: absolute;
    z-index: 10;
    height: 100vh;
  }

  .sidebar.hidden {
    display: none;
  }

  .message {
    max-width: 85%;
  }

  /* Show back button on mobile */
  .back-btn {
    display: flex;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}
