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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --bg-dark: #1f2937;
  --bg-darker: #111827;
  --bg-light: #f9fafb;
  --border: #e5e7eb;
  --text-dark: #111827;
  --text-light: #6b7280;
  --text-white: #ffffff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-light);
  color: var(--text-dark);
  overflow: hidden;
}

.container {
  display: flex;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

/* =================================
   SIDEBAR
   ================================= */

.sidebar {
  width: 320px;
  background: var(--bg-darker);
  color: var(--text-white);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #374151;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid #374151;
}

.app-title {
  margin-bottom: 15px;
}

.sidebar-header h1 {
  font-size: 20px;
  margin-bottom: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.username-display {
  font-size: 12px;
  color: #9ca3af;
  flex: 1;
}

.btn-logout {
  background: #4b5563;
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-logout:hover {
  background: var(--danger);
}

.btn-new-session {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-new-session:hover {
  background: var(--primary-hover);
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.session-item {
  padding: 15px;
  margin-bottom: 8px;
  background: #374151;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.session-item:hover {
  background: #4b5563;
}

.session-item.active {
  background: var(--primary);
  border-color: var(--primary-hover);
}

.session-item-name {
  font-weight: 600;
  margin-bottom: 5px;
  font-size: 14px;
}

.session-item-id {
  font-size: 11px;
  color: #9ca3af;
}

.session-item.active .session-item-id {
  color: #dbeafe;
}

.session-item-status {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 8px;
  font-size: 10px;
  border-radius: 4px;
  background: var(--success);
  color: white;
}

.session-item-status.encerrado {
  background: var(--text-light);
}

.sidebar-footer {
  padding: 15px;
  border-top: 1px solid #374151;
}

.btn-clear-all {
  width: 100%;
  padding: 10px;
  margin-bottom: 8px;
  background: #6b7280;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-clear-all:hover {
  background: #4b5563;
}

.btn-delete-all {
  width: 100%;
  padding: 10px;
  margin-bottom: 8px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-delete-all:hover {
  background: var(--danger-hover);
}

.btn-cleanup {
  width: 100%;
  padding: 10px;
  margin-bottom: 15px;
  background: #f59e0b;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-cleanup:hover {
  background: #d97706;
}

.chat-actions {
  display: flex;
  gap: 10px;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-light);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
}

.status-dot.connected {
  background: var(--success);
  animation: pulse 2s infinite;
}

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

/* =================================
   MAIN / CHAT
   ================================= */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  overflow: hidden;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Tela de boas-vindas */
.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.welcome-content {
  text-align: center;
  color: white;
  max-width: 500px;
  padding: 40px;
}

.welcome-content h2 {
  font-size: 32px;
  margin-bottom: 15px;
}

.welcome-content p {
  font-size: 16px;
  margin-bottom: 30px;
  opacity: 0.9;
}

/* Área de chat */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.chat-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  z-index: 10;
  flex-shrink: 0;
}

.session-info h2 {
  font-size: 18px;
  margin-bottom: 5px;
}

.session-id {
  font-size: 12px;
  color: var(--text-light);
}

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  background: #f9fafb;
}

.message {
  margin-bottom: 20px;
  display: flex;
  gap: 12px;
}

.message:first-child {
  margin-top: 0;
}

.message:last-child {
  margin-bottom: 0;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

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

.message.assistant .message-avatar {
  background: var(--success);
  color: white;
}

.message-content {
  flex: 1;
  background: white;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message.user .message-content {
  background: #dbeafe;
}

.message-text {
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-time {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 8px;
}

/* Input area */
.input-area {
  padding: 20px;
  border-top: 1px solid var(--border);
  background: white;
  display: flex;
  gap: 12px;
  flex-shrink: 0;
  z-index: 10;
}

#messageInput {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 150px;
  transition: border-color 0.2s;
}

#messageInput:focus {
  outline: none;
  border-color: var(--primary);
}

.btn-send {
  padding: 12px 24px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-send:hover:not(:disabled) {
  background: var(--primary-hover);
}

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

.kbd {
  font-size: 12px;
  opacity: 0.7;
}

/* Botões */
.btn-primary {
  padding: 12px 24px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

.btn-secondary {
  padding: 12px 24px;
  background: var(--text-light);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: #4b5563;
}

.btn-danger {
  padding: 8px 16px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

/* Custom Modals */
.custom-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.2s ease-out;
}

.custom-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.custom-modal-content {
  position: relative;
  background: white;
  border-radius: 16px;
  padding: 32px;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: slideUp 0.3s ease-out;
}

.custom-modal-icon {
  font-size: 56px;
  margin-bottom: 16px;
  animation: scaleIn 0.4s ease-out;
}

.custom-modal-icon.warning {
  font-size: 56px;
  color: #f59e0b;
}

.custom-modal-icon.success {
  font-size: 56px;
  color: var(--success);
}

.custom-modal-icon.error {
  font-size: 56px;
  color: var(--danger);
}

.custom-modal-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-dark);
}

.custom-modal-message {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-light);
  margin-bottom: 24px;
  white-space: pre-wrap;
}

.custom-modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.custom-btn {
  padding: 12px 32px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 120px;
}

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

.custom-btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.custom-btn-confirm {
  background: var(--primary);
  color: white;
}

.custom-btn-confirm:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.custom-btn-cancel {
  background: #e5e7eb;
  color: var(--text-dark);
}

.custom-btn-cancel:hover {
  background: #d1d5db;
  transform: translateY(-1px);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.5);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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

.modal-content {
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

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

.modal-header h3 {
  font-size: 18px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-dark);
}

.modal-body {
  padding: 20px;
}

.modal-body label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 14px;
}

.modal-body input {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.modal-body input:focus {
  outline: none;
  border-color: var(--primary);
}

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

/* Loading */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  animation: typing 1.4s infinite;
}

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

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
  }
  30% {
    opacity: 1;
  }
}

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

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

::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 280px;
  }
}

@media (max-width: 640px) {
  .container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    max-height: 40vh;
  }
}
