/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

/* Material Design styles are loaded separately via stylesheet_link_tag in layout */

/* Markdown prose styles - scoped to .prose class */
.prose {
  color: var(--md-on-surface);
  max-width: 65ch;
  line-height: 1.75;
}

.prose-sm {
  font-size: 0.875rem;
  line-height: 1.7142857;
}

/* Use Material Design colors for markdown */
.prose,
.prose-sm {
  color: var(--md-on-surface);
}

/* Paragraphs - normal text size, not headings */
.prose-sm p {
  margin-top: 1.1428571em;
  margin-bottom: 1.1428571em;
  color: var(--md-on-surface);
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.7142857;
  display: block;
}

.prose p {
  margin-top: 1.25em;
  margin-bottom: 1.25em;
  color: var(--md-on-surface);
}

.prose-sm p:first-child {
  margin-top: 0;
}

.prose-sm p:last-child {
  margin-bottom: 0;
}

/* Ensure paragraphs are separated with clear line breaks */
.prose-sm p + p {
  margin-top: 1.1428571em;
}

/* Ensure paragraphs after headings have proper spacing */
.prose-sm h1 + p,
.prose-sm h2 + p,
.prose-sm h3 + p,
.prose-sm h4 + p {
  margin-top: 0.8em;
}

/* Headings - only actual headings get heading styles */
.prose-sm h1,
.prose h1 {
  font-size: 1.7142857em;
  margin-top: 1.6em;
  margin-bottom: 0.8em;
  line-height: 1.3;
  font-weight: 700;
  color: var(--md-on-surface);
  border-bottom: 2px solid var(--md-outline-variant);
  padding-bottom: 0.3em;
}

.prose-sm h1:first-child,
.prose h1:first-child {
  margin-top: 0;
}

.prose-sm h2,
.prose h2 {
  font-size: 1.4285714em;
  margin-top: 1.6em;
  margin-bottom: 0.8em;
  line-height: 1.4;
  font-weight: 600;
  color: var(--md-on-surface);
  border-bottom: 1px solid var(--md-outline-variant);
  padding-bottom: 0.2em;
}

.prose-sm h3,
.prose h3 {
  font-size: 1.1428571em;
  margin-top: 1.5em;
  margin-bottom: 0.6em;
  line-height: 1.5;
  font-weight: 600;
  color: var(--md-on-surface);
}

.prose-sm h4,
.prose h4 {
  font-size: 1em;
  margin-top: 1.4em;
  margin-bottom: 0.5em;
  line-height: 1.6;
  font-weight: 600;
  color: var(--md-on-surface);
}

/* Ensure paragraphs don't inherit heading styles - override any inheritance */
.prose-sm p {
  font-size: 0.875rem !important;
  font-weight: 400 !important;
  line-height: 1.7142857 !important;
  color: var(--md-on-surface) !important;
}

/* Lists */
.prose-sm ul,
.prose-sm ol {
  margin-top: 1.1428571em;
  margin-bottom: 1.1428571em;
  padding-left: 1.5714286em;
  color: var(--md-on-surface);
  font-size: 0.875rem;
  list-style-position: outside;
  display: block;
}

.prose-sm ul {
  list-style-type: disc;
  list-style-position: outside;
}

.prose-sm ol {
  list-style-type: decimal;
  list-style-position: outside;
}

.prose-sm li {
  margin-top: 0.2857143em;
  margin-bottom: 0.2857143em;
  font-size: 0.875rem;
  display: list-item;
  list-style-position: outside;
  padding-left: 0.5em;
}

.prose-sm li > p {
  margin-top: 0.5714286em;
  margin-bottom: 0.5714286em;
}

.prose-sm li > :first-child {
  margin-top: 0;
}

.prose-sm li > :last-child {
  margin-bottom: 0;
}

/* Ensure list items have visible bullets */
.prose-sm ul li::marker,
.prose ul li::marker {
  color: var(--md-on-surface-variant);
  font-weight: normal;
}

.prose-sm ol li::marker,
.prose ol li::marker {
  color: var(--md-on-surface-variant);
  font-weight: normal;
}

/* Lists - full size */
.prose ul,
.prose ol {
  margin-top: 1.25em;
  margin-bottom: 1.25em;
  padding-left: 1.625em;
  color: var(--md-on-surface);
}

.prose ul {
  list-style-type: disc;
}

.prose ol {
  list-style-type: decimal;
}

.prose li {
  margin-top: 0.5em;
  margin-bottom: 0.5em;
  padding-left: 0.375em;
}

/* Links - moved below with !important to ensure they override parent colors */

/* Strong and emphasis */
.prose-sm strong,
.prose strong {
  font-weight: 600;
  color: var(--md-on-surface);
}

.prose-sm em,
.prose em {
  font-style: italic;
  color: var(--md-on-surface);
}

/* Code */
.prose-sm code,
.prose code {
  font-size: 0.8571429em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background-color: var(--md-surface-variant);
  padding: 0.1428571em 0.2857143em;
  border-radius: 0.25rem;
  color: var(--md-on-surface);
  font-weight: 500;
}

.prose-sm pre,
.prose pre {
  font-size: 0.8571429em;
  line-height: 1.6666667;
  margin-top: 1.6666667em;
  margin-bottom: 1.6666667em;
  border-radius: 0.5rem;
  padding: 1em;
  background-color: var(--md-surface-variant);
  overflow-x: auto;
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline-variant);
}

/* Dark mode code block adjustments */
.dark .prose-sm code,
.dark .prose code {
  background-color: var(--md-surface-container);
}

.dark .prose-sm pre,
.dark .prose pre {
  background-color: var(--md-surface-container);
  border-color: var(--md-outline);
}

.dark .prose-lg code {
  background-color: var(--md-surface-container);
}

.dark .prose-lg pre {
  background-color: var(--md-surface-container);
  border-color: var(--md-outline);
}

.prose-sm pre code {
  background-color: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

/* Blockquotes */
.prose-sm blockquote,
.prose blockquote {
  margin-top: 1.6em;
  margin-bottom: 1.6em;
  padding: 1em 1.5em;
  padding-left: 1.5em;
  border-left: 0.25em solid var(--md-primary);
  background-color: var(--md-surface-container);
  border-radius: 0 0.5rem 0.5rem 0;
  font-style: normal;
  color: var(--md-on-surface-variant);
  font-size: 0.875rem;
}

.prose blockquote {
  font-size: 1rem;
}

/* Horizontal rules */
.prose-sm hr,
.prose hr {
  margin-top: 2.8571429em;
  margin-bottom: 2.8571429em;
  border-top: 1px solid var(--md-outline-variant);
  border-bottom: none;
  border-left: none;
  border-right: none;
}

/* Tables */
.prose-sm table,
.prose table {
  width: 100%;
  margin-top: 1.1428571em;
  margin-bottom: 1.1428571em;
  border-collapse: collapse;
  font-size: 0.8571429em;
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--md-outline-variant);
}

.prose-sm th,
.prose-sm td,
.prose th,
.prose td {
  padding: 0.75em 1em;
  border: 1px solid var(--md-outline-variant);
  text-align: left;
}

.prose-sm th,
.prose th {
  font-weight: 600;
  background-color: var(--md-surface-container);
  color: var(--md-on-surface);
}

.prose-sm td,
.prose td {
  color: var(--md-on-surface);
  background-color: var(--md-surface);
}

.prose-sm tr:hover td,
.prose tr:hover td {
  background-color: var(--md-surface-variant);
}

/* Dark mode table adjustments */
.dark .prose-sm th,
.dark .prose th {
  background-color: var(--md-surface-container);
}

.dark .prose-sm tr:hover td,
.dark .prose tr:hover td {
  background-color: var(--md-surface-container);
  opacity: 0.8;
}

/* Images */
.prose-sm img {
  margin-top: 1.7142857em;
  margin-bottom: 1.7142857em;
  max-width: 100%;
  height: auto;
}

/* Remove max-width constraint when max-w-none is applied */
.prose.max-w-none {
  max-width: none;
}

/* Prose-lg styles - larger version of prose-sm */
.prose-lg {
  font-size: 1.125rem;
  line-height: 1.7777778;
}

.prose-lg p {
  margin-top: 1.3333333em;
  margin-bottom: 1.3333333em;
  color: var(--md-on-surface);
  font-size: 1.125rem;
  font-weight: 400;
  line-height: 1.7777778;
}

.prose-lg p:first-child {
  margin-top: 0;
}

.prose-lg p:last-child {
  margin-bottom: 0;
}

.prose-lg h1 {
  font-size: 2.25em;
  margin-top: 0;
  margin-bottom: 0.8888889em;
  line-height: 1.1111111;
  font-weight: 800;
  color: var(--md-on-surface);
}

.prose-lg h2 {
  font-size: 1.875em;
  margin-top: 1.6em;
  margin-bottom: 0.8888889em;
  line-height: 1.3333333;
  font-weight: 700;
  color: var(--md-on-surface);
}

.prose-lg h3 {
  font-size: 1.5em;
  margin-top: 1.6em;
  margin-bottom: 0.6666667em;
  line-height: 1.6;
  font-weight: 600;
  color: var(--md-on-surface);
}

.prose-lg h4 {
  font-size: 1.25em;
  margin-top: 1.6em;
  margin-bottom: 0.6666667em;
  line-height: 1.6;
  font-weight: 600;
  color: var(--md-on-surface);
}

.prose-lg ul,
.prose-lg ol {
  margin-top: 1.3333333em;
  margin-bottom: 1.3333333em;
  padding-left: 1.5555556em;
  color: var(--md-on-surface);
  font-size: 1.125rem;
}

.prose-lg ul {
  list-style-type: disc;
}

.prose-lg ol {
  list-style-type: decimal;
}

.prose-lg li {
  margin-top: 0.6666667em;
  margin-bottom: 0.6666667em;
  font-size: 1.125rem;
}

/* Links - Material Design primary color */
.prose-lg a,
.prose a {
  color: var(--md-primary) !important;
  text-decoration: underline;
  text-decoration-color: var(--md-primary);
  text-underline-offset: 2px;
  font-weight: 500;
  transition: opacity 0.2s ease;
}

.prose-lg a {
  font-size: 1.125rem;
}

.prose a {
  font-size: 1rem;
}

.prose-lg a:hover,
.prose a:hover {
  opacity: 0.8;
  text-decoration-thickness: 2px;
}

/* Also ensure prose-sm links override parent colors */
.prose-sm a {
  color: var(--md-primary) !important;
  text-decoration: underline;
  text-decoration-color: var(--md-primary);
  text-underline-offset: 2px;
  font-weight: 500;
  font-size: 0.875rem;
  transition: opacity 0.2s ease;
}

.prose-sm a:hover {
  opacity: 0.8;
  text-decoration-thickness: 2px;
}

.prose-lg strong {
  font-weight: 600;
  color: var(--md-on-surface);
}

.prose-lg em {
  font-style: italic;
}

.prose-lg code {
  font-size: 0.8888889em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background-color: var(--md-surface-variant);
  padding: 0.2em 0.4em;
  border-radius: 0.25rem;
  color: var(--md-on-surface);
}

.prose-lg pre {
  font-size: 0.8888889em;
  line-height: 1.75;
  margin-top: 2em;
  margin-bottom: 2em;
  border-radius: 0.375rem;
  padding: 1em 1.5em;
  background-color: var(--md-surface-variant);
  overflow-x: auto;
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline-variant);
}

.prose-lg pre code {
  background-color: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

.prose-lg blockquote {
  margin-top: 1.6em;
  margin-bottom: 1.6em;
  padding-left: 1em;
  border-left: 0.25em solid var(--md-primary);
  background-color: var(--md-surface-container);
  border-radius: 0 0.5rem 0.5rem 0;
  font-style: normal;
  color: var(--md-on-surface-variant);
  font-size: 1.125rem;
  padding: 1em 1.5em;
}

.prose-lg hr {
  margin-top: 3em;
  margin-bottom: 3em;
  border-top: 1px solid var(--md-outline-variant);
  border-bottom: none;
  border-left: none;
  border-right: none;
}

.prose-lg table {
  width: 100%;
  margin-top: 1.3333333em;
  margin-bottom: 1.3333333em;
  border-collapse: collapse;
  font-size: 1rem;
}

.prose-lg th,
.prose-lg td {
  padding: 0.6666667em;
  border: 1px solid var(--md-outline-variant);
}

.prose-lg th {
  font-weight: 600;
  background-color: var(--md-surface-container);
  color: var(--md-on-surface);
}

.prose-lg td {
  color: var(--md-on-surface);
  background-color: var(--md-surface);
}

.prose-lg img {
  margin-top: 2em;
  margin-bottom: 2em;
  max-width: 100%;
  height: auto;
}

/* Citation Tooltip */
.citation-tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted currentColor;
  opacity: 0.8;
  cursor: help;
  transition: opacity 0.2s ease-in-out;
}

.citation-tooltip:hover {
  opacity: 1;
  border-bottom-style: solid;
}

/* Citation Reference Link (for inline citations in research reports) */
.citation-reference-link {
  position: relative;
  display: inline-block;
  transition: opacity 0.2s ease-in-out;
}

.citation-reference-link:hover {
  opacity: 1;
  border-bottom-style: solid !important;
}

.citation-reference-link::before,
.citation-reference-link::after {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
  visibility: hidden;
  z-index: 1000;
}

.citation-reference-link::before {
  content: attr(data-tooltip);
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 14px;
  background-color: rgba(0, 0, 0, 0.95);
  color: white;
  border-radius: 6px;
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  max-width: 500px;
  min-width: 200px;
  word-wrap: break-word;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  text-align: left;
}

.citation-reference-link::after {
  content: "";
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.95);
}

.citation-reference-link:hover::before,
.citation-reference-link:hover::after {
  opacity: 1;
  visibility: visible;
}

@media (max-width: 640px) {
  .citation-reference-link::before {
    max-width: calc(100vw - 40px);
    left: 0;
    transform: none;
  }
  
  .citation-reference-link::after {
    left: 20px;
    transform: none;
  }
}

.citation-tooltip::before,
.citation-tooltip::after {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
  visibility: hidden;
  z-index: 1000;
}

.citation-tooltip::before {
  content: attr(data-tooltip);
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 14px;
  background-color: rgba(0, 0, 0, 0.95);
  color: white;
  border-radius: 6px;
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  max-width: 500px;
  min-width: 200px;
  word-wrap: break-word;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  text-align: left;
}

.citation-tooltip::after {
  content: "";
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.95);
}

.citation-tooltip:hover::before,
.citation-tooltip:hover::after {
  opacity: 1;
  visibility: visible;
}

/* Adjust tooltip position on smaller screens */
@media (max-width: 640px) {
  .citation-tooltip::before {
    max-width: calc(100vw - 40px);
    left: 0;
    transform: none;
  }
  
  .citation-tooltip::after {
    left: 20px;
    transform: none;
  }
}
