: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: 100%;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent; 
}
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15); 
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3); 
}

/* Layout */
.app-layout {
  display: flex;
  height: 100%;
  width: 100%;
}

/* 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;
  transition: transform 0.3s ease-in-out;
  z-index: 100;
}

.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 {
  flex: 1;
  overflow-y: auto;
  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-nav-toggle {
  display: none;
}
@media (max-width: 768px) {
  .mobile-nav-toggle, .mobile-only {
    display: inline-flex !important;
  }
}

.mobile-nav-toggle, .mobile-only {
  display: none;
}

/* 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;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.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: minmax(280px, 320px) minmax(400px, 1fr) minmax(320px, 400px);
    gap: 1.5rem;
    height: calc(100vh - 72px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
}

.panel {
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 1.25rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03), 0 1px 3px rgba(0,0,0,0.02);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 400px;
    transition: box-shadow 0.3s ease;
}
.panel:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0,0,0,0.03);
}

.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: white;
  border-top: 1px solid rgba(0,0,0,0.05);
}

.footer-container {
  display: flex;
  gap: 1rem;
  align-items: center;
  max-width: 800px;
  margin: 0 auto;
  position: relative;
}

.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: 16px; /* Prevents auto-zoom on iOS */
  font-family: inherit;
  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; }
}

.desktop-flex-col {
    display: flex;
    flex-direction: column;
}

@media (min-width: 769px) {
  .desktop-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }
  .desktop-panel-flex {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .desktop-flex-col {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }
}

/* =========================================
   RESPONSIVE ARCHITECTURE
   ========================================= */

/* Desktop (>= 1024px) */
@media (min-width: 1024px) {
  /* Grid constraint adjustments for smaller laptops */
  .dashboard-grid {
    grid-template-columns: minmax(280px, 300px) minmax(400px, 1fr) minmax(320px, 400px);
  }
}

/* Tablet & Mobile: Drawer mode for Sidebar (<= 1023px) */
@media (max-width: 1023px) {
  .app-layout { flex-direction: column; overflow: hidden; height: 100%; }
  
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px; max-width: 80%;
    transform: translateX(-100%) !important;
    box-shadow: 4px 0 10px rgba(0,0,0,0.2);
    z-index: 1000;
  }

  .sidebar.show { transform: translateX(0) !important; z-index: 1001 !important; }
  
  .sidebar-backdrop {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 999; display: none;
  }
  .sidebar-backdrop.show { display: block; }
  
  .mobile-nav-toggle, .mobile-only { 
    display: inline-flex !important; 
    position: relative !important; 
    z-index: 50 !important; 
    cursor: pointer;
    pointer-events: auto;
  }
  .mobile-nav-toggle svg, .mobile-only svg { pointer-events: none; }
  .chat-header .btn-logout { display: none; }
  
  .chat-main { flex: 1; overflow: hidden; height: 100%; display: flex; flex-direction: column; width: 100%; }
}

/* Responsiveness */
@media (max-width: 1366px) and (min-width: 769px) {
  .chat-main { overflow-y: auto !important; }
  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
    height: auto !important;
    overflow: visible !important;
    padding: 1.5rem;
  }
  .chat-transcript-panel, .medical-history-panel {
    height: 600px;
  }
  .analysis-action-wrapper {
    display: contents !important;
  }
  .clinical-analysis-panel, .prescription-panel {
    height: 550px;
  }
  .clinical-analysis-panel { order: 1; }
  .prescription-panel { order: 2; }
  .medical-history-panel { order: 3; }
  .chat-transcript-panel { order: 4; }
  .panel { overflow: hidden; }
}

.analysis-action-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 0;
}

/* Mobile Specifically (< 768px) */
@media (max-width: 767px) {
  .chat-header { height: 64px; padding: 0 1rem; gap: 0.5rem; }
  .chat-header .user-info { text-align: right; }
  .chat-header .user-name { font-size: 0.75rem; line-height: 1.25; text-align: right; }
  
  .dashboard-grid {
    grid-template-columns: 1fr;
    height: calc(100vh - 64px); overflow-y: auto;
    padding: 1rem; width: 100%; margin: 0; gap: 1rem;
    display: flex; flex-direction: column;
  }
  
  .panel { width: 100%; min-width: 0; min-height: 300px; overflow: hidden; }
  
  .chat-footer { padding: 0.75rem 1rem; background: white; }
  .footer-container { flex-direction: row; gap: 0.5rem !important; width: 100%; }
  
  .mobile-new-chat-btn {
    display: inline-flex !important; align-items: center; justify-content: center;
    background: var(--gradient-orange); color: white; border: none;
    padding: 0.4rem 0.8rem !important; font-size: 0.8rem !important;
    border-radius: 12px !important; font-weight: 700; box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  }
  
  .mic-btn, .send-btn { width: 38px; height: 38px; }
  .mic-btn { right: 54px; }
  .chat-input { padding: 0.8rem 6rem 0.8rem 1.25rem; font-size: 16px; font-family: inherit; }
  
  .doctor-layout .dashboard-grid {
    padding: 1.5rem 1rem; flex: 1; height: auto !important;
  }
  .doctor-layout .analysis-action-wrapper { display: contents !important; }
  .doctor-layout .clinical-analysis-panel { order: 1; height: 400px; }
  .doctor-layout .prescription-panel { order: 2; height: 400px; }
  .doctor-layout .medical-history-panel { order: 3; height: 500px; }
  .doctor-layout .chat-transcript-panel { order: 4; height: 500px; }
  .doctor-layout .doctor-patient-list { display: flex; flex-direction: column; overflow-x: hidden; gap: 0.5rem; padding: 0; }
  .doctor-layout .doctor-patient-list .nav-item { flex: 0 0 auto; width: 100%; text-align: left; }
}

/* Base Toggles */
.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; min-height: 48px; }
.btn-submit:hover { opacity: 0.9; }