/* Nephroclinic Document Bot - Styles */
/* Dark/Light Mode Support */

:root {
  /* Light Mode Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f5f7fa;
  --bg-tertiary: #e8ecf1;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --border-color: #e5e7eb;
  --accent-color: #2563eb;
  --accent-hover: #1d4ed8;
  --success-color: #10b981;
  --danger-color: #ef4444;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

  /* Chat Colors */
  --user-message-bg: #2563eb;
  --user-message-text: #ffffff;
  --bot-message-bg: #f3f4f6;
  --bot-message-text: #1a1a2e;
}

[data-theme="dark"] {
  /* Dark Mode Colors */
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f172a;
  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --text-tertiary: #9ca3af;
  --border-color: #374151;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --success-color: #34d399;
  --danger-color: #f87171;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);

  /* Chat Colors */
  --user-message-bg: #3b82f6;
  --user-message-text: #ffffff;
  --bot-message-bg: #1f2937;
  --bot-message-text: #f9fafb;
}

* {
  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);
  transition:
    background-color 0.3s ease,
    color 0.3s ease;
  height: 100vh;
  overflow: hidden;
}

.container {
  display: flex;
  flex-direction: row;
  height: 100vh;
  max-width: none;
  width: 100%;
  margin: 0;
  background: var(--bg-primary);
  box-shadow: none;
}

.container > div:nth-child(2) {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
  box-shadow: var(--shadow-lg);
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--accent-color);
}

.logo svg {
  color: var(--accent-color);
}

.logo h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.icon-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
  font-weight: 500;
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  transform: translateY(-1px);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* Theme Toggle Icons */
.sun-icon {
  display: block;
}

.moon-icon {
  display: none;
}

[data-theme="dark"] .sun-icon {
  display: none;
}

[data-theme="dark"] .moon-icon {
  display: block;
}

/* Chat Container */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 1.5rem;
  scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar {
  width: 8px;
}

.chat-container::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

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

.chat-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Welcome Message */
.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 2rem;
  max-width: 600px;
  margin: 0 auto;
}

.welcome-message svg {
  color: var(--accent-color);
  margin-bottom: 1.5rem;
  opacity: 0.8;
}

.welcome-message h2 {
  font-size: 1.875rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.welcome-message p {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 2rem;
}

/* Quick Actions */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.quick-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
  font-weight: 500;
}

.quick-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.quick-btn svg {
  width: 16px;
  height: 16px;
}

/* Chat Messages */
.message {
  display: flex;
  margin-bottom: 1.5rem;
  animation: slideIn 0.3s ease;
}

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

.message.user {
  justify-content: flex-end;
}

.message.bot {
  justify-content: flex-start;
}

.message-content {
  max-width: 70%;
  padding: 1rem 1.25rem;
  border-radius: 1rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.user .message-content {
  background: var(--user-message-bg);
  color: var(--user-message-text);
  border-bottom-right-radius: 0.25rem;
}

.message.bot .message-content {
  background: var(--bot-message-bg);
  color: var(--bot-message-text);
  border-bottom-left-radius: 0.25rem;
  border: 1px solid var(--border-color);
}

.message-content h1,
.message-content h2,
.message-content h3 {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

.message-content h1 {
  font-size: 1.5rem;
}
.message-content h2 {
  font-size: 1.25rem;
}
.message-content h3 {
  font-size: 1.1rem;
}

.message-content ul,
.message-content ol {
  margin-left: 1.5rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.message-content code {
  background: var(--bg-tertiary);
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  font-family: "Courier New", monospace;
  font-size: 0.875rem;
}

.message-content pre {
  background: var(--bg-tertiary);
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.message-content strong {
  font-weight: 600;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  background: var(--bot-message-bg);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  border-bottom-left-radius: 0.25rem;
  max-width: 70%;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-tertiary);
  border-radius: 50%;
  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% {
    transform: translateY(0);
    opacity: 0.7;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Input Container */
.input-container {
  padding: 1.5rem;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
}

.input-wrapper {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: 1rem;
  padding: 0.75rem 1rem;
  transition: all 0.2s ease;
}

.input-wrapper:focus-within {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#userInput {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 150px;
  line-height: 1.5;
}

#userInput::placeholder {
  color: var(--text-tertiary);
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--accent-color);
  border: none;
  border-radius: 0.75rem;
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

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

.input-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
  padding: 0 0.5rem;
}

.char-count {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/* Loading State */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Responsive Design */
@media (max-width: 768px) {
  .header {
    padding: 0.75rem 1rem;
  }

  .logo h1 {
    font-size: 1rem;
  }

  .header-right {
    gap: 0.5rem;
  }

  .icon-btn span {
    display: none;
  }

  .chat-container {
    padding: 1rem;
  }

  .message-content {
    max-width: 85%;
  }

  .welcome-message {
    padding: 2rem 1rem;
  }

  .welcome-message h2 {
    font-size: 1.5rem;
  }

  .quick-actions {
    flex-direction: column;
    width: 100%;
  }

  .quick-btn {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .logo svg {
    width: 24px;
    height: 24px;
  }

  .logo h1 {
    font-size: 0.875rem;
  }

  .icon-btn {
    padding: 0.375rem 0.5rem;
  }
}

/* Uploaded Files Section */
.uploaded-files {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  animation: slideDown 0.3s ease-out;
}

.uploaded-files-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.uploaded-files-header h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.clear-uploads-btn {
  background: none;
  border: none;
  color: var(--danger-color);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background-color 0.2s;
}

.clear-uploads-btn:hover {
  background: rgba(239, 68, 68, 0.1);
}

.uploaded-files-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.uploaded-file-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.uploaded-file-item svg {
  flex-shrink: 0;
  color: var(--accent-color);
}

.uploaded-file-item small {
  color: var(--text-tertiary);
  margin-left: auto;
}

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

/* Document Viewer Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  animation: fadeIn 0.3s ease-out;
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: 12px;
  width: 90%;
  max-width: 1200px;
  height: 90%;
  max-height: 800px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease-out;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 2rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

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

.modal-body {
  flex: 1;
  overflow: hidden;
  padding: 0;
}

#documentViewerFrame {
  width: 100%;
  height: 100%;
  border: none;
}

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

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

/* Clickable Citations */
.source-citation {
  color: var(--accent-color);
  cursor: pointer;
  text-decoration: underline;
  font-weight: 500;
  transition: all 0.2s ease;
}

.source-citation:hover {
  opacity: 0.8;
}

/* Page Citations */
.page-citation {
  color: var(--accent-color);
  cursor: pointer;
  background: var(--bg-tertiary);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
  display: inline-block;
  border: 1px solid var(--border-color);
}

.page-citation:hover {
  background: var(--accent-color);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Document Links (in parentheses) */
.doc-link {
  color: var(--accent-color);
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px dashed var(--accent-color);
  transition: all 0.2s ease;
  padding: 0 0.15rem;
}

.doc-link:hover {
  background: var(--accent-color);
  color: white;
  border-bottom-style: solid;
  border-radius: 3px;
}

/* Read More / Expandable Content */
.expandable-content {
  position: relative;
}

.expandable-content.collapsed {
  max-height: 150px;
  overflow: hidden;
}

.expandable-content.collapsed::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: linear-gradient(to bottom, transparent, var(--bg-secondary));
}

.read-more-btn {
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.read-more-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Left Sidebar for Documents */
.document-sidebar {
  width: 350px;
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-primary);
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.documents-library-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.documents-library-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.doc-section-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  padding: 0 0.25rem;
}

.doc-section-header:first-child {
  margin-top: 0;
}

.document-library-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.document-library-item.uploaded {
  border-left: 3px solid var(--success-color);
}

.document-library-item:hover {
  border-color: var(--accent-color);
  transform: translateX(2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.document-library-item svg {
  flex-shrink: 0;
  color: var(--accent-color);
}

.document-library-item .doc-info {
  flex: 1;
  min-width: 0;
}

.document-library-item .doc-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.document-library-item .doc-type {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 0.25rem;
}

/* Full Screen Document Viewer */
.document-viewer-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.2s ease-out;
}

.viewer-header-fullscreen {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.viewer-header-fullscreen h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 1rem;
}

.close-viewer-btn {
  background: var(--danger-color);
  border: none;
  font-size: 1.8rem;
  color: white;
  cursor: pointer;
  padding: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s ease;
  flex-shrink: 0;
  font-weight: 300;
  line-height: 1;
}

.close-viewer-btn:hover {
  background: #dc2626;
  transform: scale(1.05);
}

.viewer-body-fullscreen {
  flex: 1;
  overflow: hidden;
  background: var(--bg-secondary);
}

.viewer-body-fullscreen iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

/* Responsive */
@media (max-width: 1024px) {
  .document-sidebar {
    width: 300px;
  }
}

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

  .document-sidebar {
    width: 100%;
    height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
}
