/* Common styles shared across all pages */

/* Linkified document reference styles */
.document-reference {
  display: inline;
}

.inline-link {
  display: inline-block;
  margin-left: 4px;
  text-decoration: none !important;
  transition: transform 0.2s ease;
}

.inline-link:hover {
  transform: scale(1.1);
}

.google-drive-link.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.document-excerpt-container {
  margin: 12px 0;
}

.document-excerpt-container blockquote {
  margin: 0;
}

/* Excerpt tag highlight for matched phrases in tagged text */
.excerpt-tag-highlight {
  background-color: transparent;
  padding: 2px 6px;
  border: 1px solid #000;
  border-radius: 4px;
  font-weight: 500;
  box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
}

/* Excerpt tag segment for broader tagged text context */
.excerpt-tag-segment {
  background-color: #fef08a; /* yellow-200 */
  padding: 2px 4px;
  border-radius: 3px;
  font-weight: 400;
}

/* Highlight styles */
.highlight {
  background-color: #fef3c7;
  padding: 2px 4px;
  border-radius: 3px;
}

.highlight-strong {
  background-color: #fcd34d;
  font-weight: 600;
  padding: 2px 4px;
  border-radius: 3px;
}

/* Keyword highlight from search - distinct styling on top of tag highlights */
.keyword-highlight {
  position: relative;
  background-color: transparent !important; /* Transparent to show underlying tag colors */
  padding: 2px 4px;
  border-radius: 4px;
  border: 2px solid #000000; /* Black border */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); /* Black shadow */
  font-weight: 600;
  z-index: 10; /* Ensure it appears on top */
  display: inline;
}

/* Tag highlight styles - just color, no borders */
.tag-highlight {
  display: inline;
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Dropdown arrow animation */
.dropdown-arrow {
  transition: transform 0.2s;
}

.dropdown-arrow.open {
  transform: rotate(90deg);
}

/* Hamburger Menu Styles */
.hamburger-menu {
  position: relative;
}

.hamburger-icon {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  width: 24px;
  height: 18px;
  justify-content: space-between;
}

.hamburger-icon span {
  display: block;
  width: 100%;
  height: 2px;
  background-color: #374151;
  transition: all 0.3s ease;
  border-radius: 1px;
}

.hamburger-icon:hover span {
  background-color: #1f2937;
}

.hamburger-menu input[type="checkbox"] {
  display: none;
}

.hamburger-menu
  input[type="checkbox"]:checked
  + .hamburger-icon
  span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-menu
  input[type="checkbox"]:checked
  + .hamburger-icon
  span:nth-child(2) {
  opacity: 0;
}

.hamburger-menu
  input[type="checkbox"]:checked
  + .hamburger-icon
  span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -6px);
}

.hamburger-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow:
    0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05);
  min-width: 200px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  z-index: 50;
}

.hamburger-menu input[type="checkbox"]:checked ~ .hamburger-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.hamburger-dropdown a {
  display: block;
  padding: 6px 16px;
  color: #374151;
  text-decoration: none;
  border-bottom: 1px solid #f3f4f6;
  transition: background-color 0.2s ease;
}

.hamburger-dropdown a:hover {
  background-color: #f9fafb;
  color: #1f2937;
}

.hamburger-dropdown a:last-child {
  border-bottom: none;
}

.hamburger-user-info {
  padding: 8px 16px;
  border-bottom: 1px solid #e5e7eb;
  background-color: #f9fafb;
}

.hamburger-user-info .username {
  font-weight: 600;
  color: #374151;
  font-size: 14px;
}

.hamburger-user-info .user-label {
  font-size: 12px;
  color: #6b7280;
}

/* Chat-specific styles */
.prose ul {
  list-style-type: disc !important;
  margin-left: 1.5rem !important;
  margin-bottom: 1rem !important;
}

.prose ol {
  list-style-type: decimal !important;
  margin-left: 1.5rem !important;
  margin-bottom: 1rem !important;
}

.prose li {
  display: list-item !important;
}

/* Add spacing after lists when followed by other elements */
.prose ul + *,
.prose ol + * {
  margin-top: 1rem !important;
}

/* Typing animation cursor */
.typing-cursor {
  display: inline-block;
  animation: blink 1s infinite;
  color: #4f46e5; /* Indigo-600 */
  font-weight: normal;
  margin-left: 1px;
}

@keyframes blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
  background-color: white;
  margin: 5% auto;
  padding: 20px;
  border-radius: 8px;
  width: 80%;
  max-width: 800px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal.show {
  display: block;
}

/* Document page specific styles */
.metadata-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 8px;
  align-items: start; /* Top-align grid items */
}

.metadata-key {
  font-weight: 600;
  color: #374151;
}

.metadata-value {
  color: #6b7280;
}

.document-row {
  transition: background-color 0.2s;
}

.document-row:hover {
  background-color: #f9fafb;
}

.sortable-header {
  cursor: pointer;
  user-select: none;
}

.sortable-header:hover {
  background-color: #e5e7eb;
}

.sort-indicator {
  font-size: 0.8em;
}

/* Common markdown-html styling for consistent presentation across document metadata and chat bubbles */
.markdown-html {
  line-height: 1.6;
  color: #374151; /* gray-700 */
}

/* Headers with proper hierarchy, bold styling, and spacing */
.markdown-html h1 {
  font-size: 1.875rem; /* 30px */
  font-weight: 700; /* bold */
  margin-top: 1.5rem;
  margin-bottom: 1rem;
  color: #111827; /* gray-900 */
}

.markdown-html h2 {
  font-size: 1.5rem; /* 24px */
  font-weight: 700; /* bold */
  margin-top: 1.5rem;
  margin-bottom: 1rem;
  color: #111827; /* gray-900 */
}

.markdown-html h3 {
  font-size: 1.25rem; /* 20px */
  font-weight: 600; /* semibold */
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
  color: #111827; /* gray-900 */
}

.markdown-html h4 {
  font-size: 1.125rem; /* 18px */
  font-weight: 600; /* semibold */
  margin-top: 1rem;
  margin-bottom: 0.75rem;
  color: #111827; /* gray-900 */
}

.markdown-html h5 {
  font-size: 1rem; /* 16px */
  font-weight: 600; /* semibold */
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  color: #111827; /* gray-900 */
}

.markdown-html h6 {
  font-size: 0.875rem; /* 14px */
  font-weight: 600; /* semibold */
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  color: #374151; /* gray-700 */
}

/* Paragraphs with proper spacing */
.markdown-html p {
  margin-bottom: 1rem;
}

/* Lists with proper spacing and formatting */
.markdown-html ul,
.markdown-html ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.markdown-html ul {
  list-style-type: disc;
}

.markdown-html ol {
  list-style-type: decimal;
}

.markdown-html li {
  margin-bottom: 0.25rem;
}

.markdown-html li > ul,
.markdown-html li > ol {
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
}

/* Code blocks with word-wrapping to prevent overflow */
.markdown-html code {
  background-color: #f3f4f6; /* gray-100 */
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
  font-size: 0.875rem;
  /* Critical: Enable word wrapping for code blocks */
  word-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.markdown-html pre {
  background-color: #f3f4f6; /* gray-100 */
  padding: 1rem;
  border-radius: 0.375rem;
  overflow-x: auto;
  margin-bottom: 1rem;
  /* Override default pre formatting to allow wrapping */
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
}

.markdown-html pre code {
  background-color: transparent;
  padding: 0;
  border-radius: 0;
}

/* Blockquotes with left border styling */
.markdown-html blockquote {
  border-left: 2px solid #9ca3af; /* gray-400 - medium gray */
  padding-left: 1rem;
  margin: 1rem 0;
  font-style: normal; /* Changed from italic to normal */
  color: #000000; /* black */
}

/* Tables with proper styling */
.markdown-html table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.markdown-html th,
.markdown-html td {
  padding: 0.5rem 0.75rem;
  border: 1px solid #9ca3af; /* gray-400 - medium gray borders */
  vertical-align: top; /* Top-aligned cells */
  text-align: left;
}

.markdown-html th {
  background-color: #dbeafe; /* blue-100 - very light blue background for headers */
  font-weight: 600;
  color: #1e40af; /* blue-800 */
}

.markdown-html tr:nth-child(even) {
  background-color: #f9fafb; /* gray-50 - subtle striping */
}

/* Links */
.markdown-html a {
  color: #2563eb; /* blue-600 */
  text-decoration: underline;
}

.markdown-html a:hover {
  color: #1d4ed8; /* blue-700 */
}

/* Strong and emphasis */
.markdown-html strong {
  font-weight: 700;
}

.markdown-html em {
  font-style: italic;
}

/* Horizontal rules */
.markdown-html hr {
  border: none;
  border-top: 1px solid #d1d5db; /* gray-300 */
  margin: 1.5rem 0;
}

/* Image styling */
.markdown-html img {
  max-width: 100%;
  height: auto;
  margin: 0.5rem 0;
}

/* Response time badge */
.response-time-badge {
  position: absolute;
  bottom: 1px;
  right: 12px;
  font-size: 11px;
  font-style: italic;
  color: #9ca3af; /* gray-400 */
  background-color: white;
  padding: 0 4px;
}

/* Document list container styles */
.document-list-container {
  margin: 0.5rem 0;
}

/* Excerpt expando styles */
.document-excerpt-container blockquote {
  position: relative;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.document-excerpt-container blockquote.collapsed {
  max-height: 8.5em; /* Approximately 6-7 lines */
}

.document-excerpt-container blockquote.expanded {
  max-height: none;
}

.document-excerpt-container .excerpt-toggle {
  display: inline-block;
  margin-top: 0.5rem;
  color: #2563eb; /* blue-600 */
  cursor: pointer;
  font-size: 0.875rem;
  text-decoration: underline;
  transition: color 0.2s ease;
}

.document-excerpt-container .excerpt-toggle:hover {
  color: #1d4ed8; /* blue-700 */
}

/* Fade effect for collapsed excerpts */
.document-excerpt-container blockquote.collapsed::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1.5em;
  background: linear-gradient(
    to bottom,
    rgba(251, 255, 252, 0),
    rgba(251, 255, 252, 1)
  ); /* very light green fade */
  pointer-events: none;
}

/* Bold list markers/numbers for markdown content */
.markdown-html ol {
  list-style-position: outside; /* Ensure numbers are outside the content */
}

.markdown-html ol li::marker {
  font-weight: 700; /* Bold the numbers */
}

/* Ensure proper text wrapping that doesn't flow under the list markers */
.markdown-html ol li,
.markdown-html ul li {
  margin-left: 0; /* Reset any default margin */
  padding-left: 0.25rem; /* Small padding between marker and content */
}

/* Gradual reveal animation for AI responses */
@keyframes revealLine {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.assistant-message .markdown-html.reveal-animation {
  overflow: hidden;
}

.assistant-message .markdown-html.reveal-animation > * {
  opacity: 0;
  animation: revealLine 1s ease-out forwards;
}

/* Apply staggered animation delays to child elements */
.assistant-message .markdown-html.reveal-animation > *:nth-child(1) {
  animation-delay: 0ms;
}
.assistant-message .markdown-html.reveal-animation > *:nth-child(2) {
  animation-delay: 200ms;
}
.assistant-message .markdown-html.reveal-animation > *:nth-child(3) {
  animation-delay: 400ms;
}
.assistant-message .markdown-html.reveal-animation > *:nth-child(4) {
  animation-delay: 600ms;
}
.assistant-message .markdown-html.reveal-animation > *:nth-child(5) {
  animation-delay: 800ms;
}
.assistant-message .markdown-html.reveal-animation > *:nth-child(6) {
  animation-delay: 1000ms;
}
.assistant-message .markdown-html.reveal-animation > *:nth-child(7) {
  animation-delay: 1200ms;
}
.assistant-message .markdown-html.reveal-animation > *:nth-child(8) {
  animation-delay: 1400ms;
}
.assistant-message .markdown-html.reveal-animation > *:nth-child(9) {
  animation-delay: 1600ms;
}
.assistant-message .markdown-html.reveal-animation > *:nth-child(10) {
  animation-delay: 1800ms;
}

/* For elements beyond 10, use a formula */
.assistant-message .markdown-html.reveal-animation > *:nth-child(n + 11) {
  animation-delay: 2000ms;
}

/* Special handling for inline elements within paragraphs */
.assistant-message .markdown-html.reveal-animation p {
  line-height: 1.8;
}

/* For list items, apply animation to each li */
.assistant-message .markdown-html.reveal-animation ul li,
.assistant-message .markdown-html.reveal-animation ol li {
  opacity: 0;
  animation: revealLine 1s ease-out forwards;
}

.assistant-message .markdown-html.reveal-animation ul li:nth-child(1),
.assistant-message .markdown-html.reveal-animation ol li:nth-child(1) {
  animation-delay: 200ms;
}
.assistant-message .markdown-html.reveal-animation ul li:nth-child(2),
.assistant-message .markdown-html.reveal-animation ol li:nth-child(2) {
  animation-delay: 400ms;
}
.assistant-message .markdown-html.reveal-animation ul li:nth-child(3),
.assistant-message .markdown-html.reveal-animation ol li:nth-child(3) {
  animation-delay: 600ms;
}
.assistant-message .markdown-html.reveal-animation ul li:nth-child(4),
.assistant-message .markdown-html.reveal-animation ol li:nth-child(4) {
  animation-delay: 800ms;
}
.assistant-message .markdown-html.reveal-animation ul li:nth-child(5),
.assistant-message .markdown-html.reveal-animation ol li:nth-child(5) {
  animation-delay: 1000ms;
}
.assistant-message .markdown-html.reveal-animation ul li:nth-child(n + 6),
.assistant-message .markdown-html.reveal-animation ol li:nth-child(n + 6) {
  animation-delay: 1200ms;
}
