:root {
  --bg-dark: #1E1F3D;
  --bg-light: #F3F4FB;
  --primary-accent: #4A4EA7;
  --gradient-orange: linear-gradient(135deg, #FBA12E 0%, #FF8A00 100%);
  --bubble-user: #37BEF8;
  --bubble-ai: #FFFFFF;
  --text-primary: #111827;
  --text-secondary: #9CA3AF;
  --text-light: #FFFFFF;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

body, html {
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-light);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: 25%;
  min-width: 280px;
  max-width: 320px;
  background-color: var(--bg-dark);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
}

.sidebar-header {
  margin-bottom: 2rem;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  font-size: 1.25rem;
}

.icon-square {
  width: 24px;
  height: 24px;
  background-color: var(--primary-accent);
  border-radius: 6px;
  display: inline-block;
}
.icon-square-sm {
  width: 28px;
  height: 28px;
  background-color: var(--primary-accent);
  border-radius: 6px;
  display: inline-block;
}

.btn-primary-gradient {
  background: var(--gradient-orange);
  color: white;
  border: none;
  border-radius: 24px;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  width: 100%;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-md);
  margin-top: 1.5rem;
}

.btn-primary-gradient:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 8px -1px rgba(0, 0, 0, 0.15);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.nav-group-title {
  font-size: 0.75rem;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  margin: 0;
  margin-top: 1.5rem;
}

.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-item {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background-color 0.2s;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
  background-color: var(--primary-accent);
  font-weight: 500;
}

.mobile-new-chat {
  display: none !important;
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--bg-light);
}

.chat-header {
  height: 72px;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  background: white;
  z-index: 10;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.icon-btn:hover {
  background-color: var(--bg-light);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.user-name {
  font-weight: 600;
  font-size: 0.875rem;
}

.user-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.btn-logout {
  background: #fee2e2;
  color: #b91c1c;
  border: none;
  padding: 0.25rem 0.75rem;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.25rem;
  transition: background 0.2s;
}

.btn-logout:hover {
  background: #fecaca;
}

.user-avatar {
  width: 40px;
  height: 40px;
  background-color: #E5E7EB;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text-primary);
}

.history-item-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-date {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* Dashboard styles */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: calc(100vh - 72px);
    overflow: hidden;
    padding: 1.5rem;
}

.panel {
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 1.25rem;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    background: #fafafa;
}

.panel-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* Chat Messages */
.chat-messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scroll-behavior: smooth;
}

.message-row {
  display: flex;
  gap: 1rem;
  max-width: 85%;
  align-items: flex-end;
}

.row-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.row-ai {
  align-self: flex-start;
}

.avatar-ai {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-bubble {
  padding: 1rem 1.25rem;
  border-radius: 20px;
  font-size: 0.9375rem;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
}

.bubble-user {
  background-color: var(--bubble-user);
  color: white;
  border-bottom-right-radius: 4px;
}

.bubble-ai {
  background-color: var(--bubble-ai);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-secondary);
}

.empty-state h2 {
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

/* Footer / Input */
.chat-footer {
  padding: 1.5rem 2rem;
  background: transparent;
}

.footer-container {
  display: flex;
  gap: 1rem;
  align-items: center;
  max-width: 800px;
  margin: 0 auto;
}

.input-form {
  position: relative;
  flex: 1;
  margin: 0;
}

.chat-input {
  width: 100%;
  padding: 1.25rem 6.5rem 1.25rem 1.5rem;
  border-radius: 9999px;
  border: 1px solid rgba(0,0,0,0.1);
  box-shadow: var(--shadow-sm);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input:focus {
  border-color: var(--primary-accent);
  box-shadow: 0 0 0 3px rgba(74, 78, 167, 0.1);
}

.send-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background-color: var(--primary-accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  transform: translateY(-50%) scale(1.05);
}

.mic-btn {
  position: absolute;
  right: 60px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.2s, transform 0.2s;
}

.mic-btn:hover {
  transform: translateY(-50%) scale(1.1);
}

.mic-btn.recording svg {
  color: #ef4444;
  animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* Responsiveness */
@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
    overflow: hidden;
    height: 100vh;
  }
  
  .sidebar {
    display: none !important; /* Hide sidebar entirely on mobile to focus on chat */
  }
  
  .chat-main {
    flex: 1;
    overflow: hidden;
    height: auto;
    display: flex;
    flex-direction: column;
  }

  .chat-header {
    height: 60px;
    padding: 0 1rem;
  }

  .mobile-new-chat {
    display: block !important;
  }

  .chat-messages-container {
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    height: auto;
    overflow-y: auto;
    padding: 1rem;
  }

  .chat-footer {
    padding: 0.5rem;
    background: transparent;
    border-top: none;
  }

  .footer-container {
    flex-direction: column;
    gap: 0.5rem !important;
  }

  .mobile-new-chat-btn {
    display: inline-block !important;
    background: var(--gradient-orange);
    color: white;
    border: none;
    padding: 0.5rem 1rem !important;
    font-size: 0.85rem !important;
    border-radius: 20px !important;
    font-weight: 700;
    margin-left: 0.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  }

  .header-left {
    display: flex;
    align-items: center;
  }

  /* Make the mic and send buttons a bit smaller on tiny screens if needed */
  .mic-btn, .send-btn {
    width: 36px;
    height: 36px;
  }
  .mic-btn { right: 54px; }
  .chat-input { padding-right: 6rem; }

  /* Doctor Specific Mobile Layout - Horizontal Selector */
  .doctor-layout .sidebar {
    display: block !important;
    width: 100%;
    height: auto;
    max-height: none;
    background: var(--bg-dark);
    padding: 0.5rem 1rem;
    border-right: none;
    border-bottom: 2px solid rgba(255,255,255,0.05);
    order: -1; /* Keep it at the very top */
  }

  .doctor-layout .sidebar-header, 
  .doctor-layout .doctor-sidebar-title {
    display: none !important;
  }

  .doctor-layout .doctor-patient-list {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    gap: 0.75rem;
    padding: 0.5rem 0;
    margin: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Hide scrollbar for clean look */
  }

  .doctor-layout .doctor-patient-list::-webkit-scrollbar {
    display: none;
  }

  .doctor-layout .doctor-patient-list .nav-item {
    flex: 0 0 auto;
    min-width: 120px;
    margin: 0 !important;
    padding: 0.75rem 1.25rem !important;
    border-radius: 99px !important;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.1);
    text-align: center;
    transition: all 0.2s;
  }

  .doctor-layout .doctor-patient-list .nav-item.active {
    background: var(--gradient-orange) !important;
    border-color: transparent;
    transform: scale(1.05);
  }

  .doctor-layout .nav-item > div:last-child {
    font-size: 0.6rem !important;
    margin-top: 0.1rem;
  }

  .doctor-layout .chat-header {
    height: auto;
    flex-direction: column;
    padding: 1rem;
    align-items: flex-start;
    gap: 0.75rem;
    background: white;
    border-bottom: 1px solid rgba(0,0,0,0.05);
  }

  .doctor-layout .header-left h2 {
    font-size: 1.25rem;
    margin: 0;
    color: var(--text-primary);
  }

  .doctor-layout .user-profile {
    align-self: flex-start;
    width: 100%;
    justify-content: space-between;
    margin-top: 0;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(0,0,0,0.05);
  }

  .doctor-layout .dashboard-grid {
    padding: 1rem;
    gap: 1.5rem;
  }
}

.mobile-new-chat-btn {
  display: none;
}
.typing-indicator span {
  display: inline-block;
  width: 6px;
  height: 6px;
  background-color: var(--text-secondary);
  border-radius: 50%;
  margin: 0 2px;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.urgency-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.urgency-High { background: #fee2e2; color: #b91c1c; }
.urgency-Medium { background: #fef3c7; color: #b45309; }
.urgency-Low { background: #d1fae5; color: #047857; }

.btn-submit {
    background-color: var(--text-primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-submit:hover {
    opacity: 0.9;
}