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

:root {
  --primary-bg: #0a0a0f;
  --secondary-bg: #12121a;
  --card-bg: #1a1a24;
  --border-color: #2a2a3a;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --accent-1: #667eea;
  --accent-2: #764ba2;
  --accent-3: #f093fb;
  --accent-4: #4facfe;
}

body {
  font-family: Arial, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--primary-bg);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==================== LOGIN SCREEN ==================== */
#login-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: radial-gradient(circle at 50% 50%, #1a1a2e 0%, #0a0a0f 100%);
  position: relative;
  overflow: hidden;
}

#login-screen::before {
  content: '';
  position: absolute;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(102, 126, 234, 0.3) 0%, transparent 70%);
  top: -200px;
  left: -200px;
  animation: float 8s ease-in-out infinite;
}

#login-screen::after {
  content: '';
  position: absolute;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(118, 75, 162, 0.2) 0%, transparent 70%);
  bottom: -150px;
  right: -150px;
  animation: float 10s ease-in-out infinite reverse;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(50px, 50px); }
}

.login-container {
  background: rgba(26, 26, 36, 0.8);
  backdrop-filter: blur(20px);
  padding: 50px 40px;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
  min-width: 380px;
  border: 1px solid rgba(102, 126, 234, 0.2);
  position: relative;
  z-index: 1;
}

.login-container h1 {
  font-size: 2rem;
  font-weight: normal;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: 2px;
  text-transform: lowercase;
}

.login-container p {
  color: var(--text-secondary);
  margin-bottom: 35px;
  font-size: 1rem;
  letter-spacing: 1px;
}

#login-form input {
  width: 100%;
  padding: 16px 20px;
  font-size: 15px;
  background: rgba(18, 18, 26, 0.6);
  border: 2px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  margin-bottom: 18px;
  transition: all 0.3s;
}

#login-form input:focus {
  outline: none;
  border-color: var(--accent-1);
  background: rgba(18, 18, 26, 0.9);
  box-shadow: 0 0 20px rgba(102, 126, 234, 0.2);
}

#login-form button {
  width: 100%;
  padding: 16px;
  font-size: 15px;
  background: linear-gradient(135deg, var(--accent-1) 0%, var(--accent-2) 100%);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#login-form button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
}

.error {
  color: #ff6b6b;
  font-size: 13px;
  margin-top: 12px;
  display: none;
  padding: 8px;
  background: rgba(255, 107, 107, 0.1);
  border-radius: 6px;
}

.error.show {
  display: block;
}

/* ==================== CHAT INTERFACE ==================== */
#chat-screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header {
  background: var(--secondary-bg);
  padding: 14px 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.header h1 {
  font-size: 1.2rem;
  color: var(--text-primary);
  font-weight: normal;
  letter-spacing: 1px;
}

.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ==================== COLLAPSIBLE SIDEBAR ==================== */
.sessions-sidebar {
  width: 260px;
  background: var(--secondary-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  position: relative;
  flex-shrink: 0;
}

.sessions-sidebar.collapsed {
  width: 0;
  overflow: hidden;
}

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

.sidebar-header h3 {
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}

.toggle-sidebar-btn {
  position: absolute;
  right: -28px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--secondary-bg);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 24px;
  height: 44px;
  border-radius: 0 7px 7px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 10;
  font-size: 11px;
}

.toggle-sidebar-btn:hover {
  background: var(--accent-1);
  color: white;
  border-color: var(--accent-1);
}

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

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-btn {
  width: 100%;
  padding: 10px 14px;
  background: rgba(102, 126, 234, 0.1);
  color: var(--accent-1);
  border: 1px solid var(--accent-1);
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 12px;
  text-align: center;
}

.sidebar-btn:hover {
  background: var(--accent-1);
  color: white;
  transform: translateY(-1px);
}

#session-list {
  list-style: none;
}

#session-list li {
  padding: 10px 12px;
  background: rgba(26, 26, 36, 0.5);
  margin-bottom: 6px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.8rem;
  border: 1px solid transparent;
  color: var(--text-secondary);
}

#session-list li:hover {
  background: rgba(102, 126, 234, 0.1);
  border-color: var(--accent-1);
  color: var(--text-primary);
}

#session-list li.active {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.2), rgba(118, 75, 162, 0.2));
  border-color: var(--accent-1);
  color: var(--text-primary);
  font-weight: 500;
}

/* ==================== CHAT CONTAINER ==================== */
.chat-container {
  flex: 1;
  background: var(--primary-bg);
  padding: 0;
  overflow: hidden;
  position: relative;
  min-height: 0; /* Allow flex child to shrink */
}

/* Messages Area - Takes all space, flows bottom-up, positioned absolutely */
#messages {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20px;
  padding-left: 60px;
  padding-right: 60px;
  padding-bottom: 160px; /* Space for fixed input at bottom */
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse; /* Flow bottom-up like CLI */
  gap: 14px;
  background: var(--primary-bg);
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 65%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.5;
  animation: messageSlideIn 0.2s ease;
  font-size: 0.9rem;
}

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

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: white;
  box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}

.message.assistant {
  align-self: flex-start;
  background: rgba(26, 26, 36, 0.8);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.message.system {
  align-self: center;
  background: rgba(102, 126, 234, 0.1);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-style: italic;
  border: 1px solid rgba(102, 126, 234, 0.2);
  padding: 8px 14px;
}

.message pre {
  background: rgba(10, 10, 15, 0.8);
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
}

.message code {
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
}

/* Thinking indicator */
.thinking-indicator {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 12px 16px !important;
}

.thinking-indicator .dot {
  width: 8px;
  height: 8px;
  background: var(--accent-1);
  border-radius: 50%;
  animation: thinking-pulse 1.4s ease-in-out infinite;
}

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

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

@keyframes thinking-pulse {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ==================== INPUT CONTAINER - FIXED AT BOTTOM ==================== */
.input-container-wrapper {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  background: var(--primary-bg);
  display: flex;
  justify-content: center; /* Center the input container */
  z-index: 10;
}

.input-container-wrapper::before {
  content: '';
  position: absolute;
  top: 17px;
  left: 50%;
  transform: translateX(-50%);
  width: min(800px, calc(100% - 80px)); /* Max 800px, responsive */
  bottom: 17px;
  border-radius: 14px;
  padding: 3px;
  background: linear-gradient(
    135deg,
    var(--accent-1),
    var(--accent-3),
    var(--accent-4),
    var(--accent-2),
    var(--accent-1)
  );
  background-size: 400% 400%;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: gradient-shift 6s ease infinite;
  pointer-events: none;
}

@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.message-input-area {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px; /* Reduced gap between rows */
  position: relative;
  z-index: 1;
  width: min(800px, calc(100% - 80px)); /* Max 800px, responsive */
}

/* ==================== MESSAGE INPUT ROW (TOP) ==================== */
#message-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-wrapper {
  flex: 1;
  position: relative;
}

#message-input {
  width: 100%;
  padding: 11px 45px 11px 14px;
  font-size: 13px;
  background: var(--card-bg); /* Same as container for unified look */
  color: var(--text-primary);
  border: none; /* Remove internal border */
  border-radius: 9px;
  transition: all 0.3s;
  font-family: Arial, sans-serif;
}

#message-input:focus {
  outline: none;
  background: var(--card-bg); /* Keep same background on focus */
}

#message-input::placeholder {
  color: var(--text-secondary);
  font-size: 12px;
}

.voice-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  background: transparent;
  border: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
  color: var(--text-secondary);
}

.voice-btn:hover {
  background: rgba(102, 126, 234, 0.1);
  color: var(--accent-1);
}

.voice-btn.active {
  background: var(--accent-1);
  color: white;
  animation: pulse 1.5s ease infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.7); }
  50% { box-shadow: 0 0 0 6px rgba(102, 126, 234, 0); }
}

.upload-btn {
  width: 38px;
  height: 38px;
  background: transparent;
  border: none; /* Remove internal border */
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.upload-btn:hover {
  background: rgba(102, 126, 234, 0.1);
  color: var(--accent-1);
}

.upload-btn.has-files {
  background: rgba(102, 126, 234, 0.2);
  color: var(--accent-1);
}

.send-btn {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border: none;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
  color: white;
  flex-shrink: 0;
}

.send-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
}

/* ==================== CONTROLS ROW (BOTTOM) - MINIMAL ==================== */
.input-controls {
  display: flex;
  gap: 10px;
}

.control-group {
  flex: 1;
}

.control-group select {
  width: 100%;
  padding: 7px 10px;
  background: var(--card-bg); /* Same background as container */
  border: none; /* Remove all borders */
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.3s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23a0a0b8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 24px;
  border-radius: 6px;
}

.control-group select:focus {
  outline: none;
  background: var(--card-bg);
  color: var(--text-primary);
}

.control-group select:hover {
  background: rgba(102, 126, 234, 0.05);
  color: var(--text-primary);
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
  width: 7px;
}

::-webkit-scrollbar-track {
  background: rgba(18, 18, 26, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: rgba(102, 126, 234, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(102, 126, 234, 0.5);
}

/* ==================== MOBILE RESPONSIVENESS ==================== */
@media (max-width: 768px) {
  .sessions-sidebar {
    position: fixed;
    left: 0;
    top: 51px;
    height: calc(100vh - 51px);
    z-index: 1000;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
  }
  
  .sessions-sidebar.collapsed {
    transform: translateX(-100%);
  }
  
  .header {
    padding: 10px 18px;
  }
  
  #messages {
    padding: 15px 20px;
    gap: 12px;
  }
  
  .input-container-wrapper {
    padding: 15px 10px;
  }
  
  .input-container-wrapper::before {
    top: 12px;
    width: calc(100% - 20px);
    bottom: 12px;
  }
  
  .message-input-area {
    width: calc(100% - 20px);
  }
  
  .message {
    max-width: 80%;
    padding: 10px 14px;
    font-size: 0.85rem;
  }
  
  .input-controls {
    flex-direction: column;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .login-container {
    min-width: 85%;
    padding: 35px 25px;
  }
  
  .header h1 {
    font-size: 1rem;
  }
  
  .btn-secondary {
    padding: 6px 10px;
    font-size: 0.7rem;
  }
  
  #messages {
    padding: 12px 15px;
  }
  
  .input-container-wrapper {
    padding: 12px 10px;
  }
  
  .input-container-wrapper::before {
    top: 9px;
    width: calc(100% - 20px);
    bottom: 9px;
  }
  
  .message-input-area {
    width: calc(100% - 20px);
  }
  
  .message {
    max-width: 85%;
    font-size: 0.8rem;
  }
  
  #message-input {
    font-size: 12px;
    padding: 9px 40px 9px 12px;
  }
}

@media (hover: none) and (pointer: coarse) {
  .btn-secondary,
  .toggle-sidebar-btn,
  .voice-btn,
  .upload-btn,
  .send-btn {
    min-height: 44px;
    min-width: 44px;
  }
  
  input,
  select {
    font-size: 16px !important;
  }
}
