/* Enhanced Markdown Styling */
.markdown-content {
  line-height: 1.7;
  color: #374151;
}

/* Headings */
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
  color: #0d9488; /* teal-600 */
  margin-top: 2rem;
  margin-bottom: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.markdown-content h1,
.markdown-content h2 {
  border-bottom: 2px solid #14b8a6; /* teal-500 */
  padding-bottom: 0.5rem;
}

.markdown-content h1 { font-size: 2.25rem; }
.markdown-content h2 { font-size: 1.875rem; }
.markdown-content h3 { font-size: 1.5rem; }
.markdown-content h4 { font-size: 1.25rem; }
.markdown-content h5 { font-size: 1.125rem; }
.markdown-content h6 { 
  font-size: 1rem; 
  color: #6b7280;
}

/* Paragraphs and Text */
.markdown-content p {
  margin-bottom: 1.25rem;
  line-height: 1.8;
}

.markdown-content strong, 
.markdown-content b {
  font-weight: 600;
  color: #115e59; /* teal-800 */
}

.markdown-content em,
.markdown-content i {
  font-style: italic;
  color: #7c2d12; /* amber-900 */
}

.markdown-content del,
.markdown-content s {
  text-decoration: line-through;
  color: #9ca3af;
}

/* Links */
.markdown-content a {
  color: #0ea5e9; /* sky-500 */
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s ease-in-out;
  border-radius: 0.25rem;
  padding: 0.1rem 0.2rem;
}

.markdown-content a:hover {
  color: #0284c7; /* sky-600 */
  text-decoration: underline;
  background-color: #f0f9ff; /* sky-50 */
}

.markdown-content a.citation-link {
  font-family: 'Inter', sans-serif;
  font-size: 0.6em;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  bottom: 3px;
  background-color: #f0fdfa; /* teal-50 */
  color: #0f766e; /* teal-700 */
  width: 1.8em;
  height: 1.8em;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #ccfbf1; /* teal-100 */
  margin: 0 0.2rem;
  line-height: 1;
  text-decoration: none;
}

.markdown-content a.citation-link:hover {
  background-color: #ccfbf1; /* teal-100 */
  color: #134e4a; /* teal-900 */
  text-decoration: none;
}

.markdown-content a[href^="http"]:not(.citation-link)::after {
  content: '\f35d';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 0.75em;
  margin-inline-start: 0.3rem;
  vertical-align: middle;
  opacity: 0.6;
  display: inline-block;
  transition: opacity 0.2s;
}

.markdown-content a[href^="http"]:not(.citation-link):hover::after {
  opacity: 1;
}

/* Lists */
.markdown-content ul,
.markdown-content ol {
  padding-inline-start: 0;
  margin-bottom: 1.25rem;
  list-style: none;
}

.markdown-content li {
  position: relative;
  margin-bottom: 0.75rem;
  padding-inline-start: 2rem;
}

.markdown-content ul > li::before {
  content: '\f104'; /* Font Awesome Chevron Left, appears as right arrow in RTL */
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  inset-inline-start: 0;
  top: 1px;
  font-size: 0.9em;
  color: #14b8a6; /* teal-500 */
  padding-right: 10px;
}

.markdown-content ol {
  counter-reset: item;
}

.markdown-content ol > li {
  counter-increment: item;
}

.markdown-content ol > li::before {
  content: counter(item);
  position: absolute;
  inset-inline-start: 0;
  top: 2px;
  width: 1.4rem;
  height: 1.4rem;
  background-color: #f0fdfa;
  color: #0f766e;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  font-size: 0.75em;
}

/* Task Lists */
.markdown-content ul.contains-task-list {
  list-style: none;
  padding-inline-start: 0;
}

.markdown-content .task-list-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.markdown-content .task-list-item input[type="checkbox"] {
  margin-top: 0.3rem;
}

/* Code */
.markdown-content code {
  background-color: #f3f4f6; /* gray-100 */
  color: #be123c; /* rose-700 */
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  font-family: monospace;
  font-size: 0.9em;
}

.markdown-content pre {
  background-color: #f9fafb; /* gray-50 */
  padding: 1.25rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  border: 1px solid #e5e7eb; /* gray-200 */
  margin: 1.5rem 0;
  direction: ltr;
  text-align: left;
}

.markdown-content pre code {
  background-color: transparent;
  padding: 0;
  color: #111827; /* gray-900 */
  font-size: 0.875rem;
}

/* Blockquotes */
.markdown-content blockquote {
  border-inline-start: 5px solid #14b8a6; /* teal-500 */
  padding: 1rem 1.5rem;
  margin: 1.5rem 0;
  background-color: #f0fdfa; /* teal-50 */
  color: #134e4a; /* teal-900 */
  border-radius: 0.5rem;
}

.markdown-content blockquote p {
  margin-bottom: 0;
}

.markdown-content blockquote :last-child {
  margin-bottom: 0;
}

/* Tables */
.markdown-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  direction: rtl;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  border: 1px solid #d1d5db;
}

.markdown-content th,
.markdown-content td {
  padding: 1rem 1.25rem;
  text-align: right !important;
  border-bottom: 1px solid #e5e7eb; /* gray-200 */
  vertical-align: top;
}

.markdown-content tr:last-child td {
  border-bottom: none;
}

.markdown-content th {
  background-color: #0d9488; /* teal-600 */
  color: white;
  font-weight: 700;
  border-bottom: 2px solid #0f766e; /* teal-700 */
  vertical-align: middle;
}

.markdown-content th strong {
  color: inherit;
  font-weight: inherit;
}

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

.markdown-content tr:hover {
  background-color: #f0fdfa; /* teal-50 */
}

.markdown-content td:first-child {
  font-weight: 600;
  color: #0f766e; /* teal-700 */
  vertical-align: middle;
  border-inline-end: 1px solid #e5e7eb;
  width: 25%;
  min-width: 120px;
}

/* Horizontal Rules */
.markdown-content hr {
  border-top: 1px solid #d1d5db; /* gray-300 */
  margin: 2.5rem 0;
  height: 1px;
  background-color: #e5e7eb;
  border: none;
}

/* Images */
.markdown-content img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  margin: 1.5rem 0;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

/* Keyboard Input */
.markdown-content kbd {
  background-color: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  color: #374151;
  display: inline-block;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.75em;
  line-height: 1;
  padding: 0.25rem 0.4rem;
  white-space: nowrap;
}

/* Highlight */
.markdown-content mark {
  background-color: #fef3c7; /* amber-100 */
  color: #92400e; /* amber-800 */
  padding: 0.1rem 0.2rem;
  border-radius: 0.25rem;
}

/* Subscript and Superscript */
.markdown-content sub,
.markdown-content sup {
  font-size: 0.75em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

.markdown-content sup {
  top: -0.5em;
}

.markdown-content sub {
  bottom: -0.25em;
}

/* Footnotes */
.markdown-content .footnotes {
  border-top: 1px solid #e5e7eb;
  margin-top: 2rem;
  padding-top: 1rem;
  font-size: 0.875rem;
}

.markdown-content .footnotes ol {
  padding-inline-start: 1.5rem;
}

.markdown-content .footnotes li {
  margin-bottom: 0.5rem;
}

/* Definition Lists */
.markdown-content dl {
  margin: 1.5rem 0;
}

.markdown-content dt {
  font-weight: 700;
  color: #0f766e;
  margin-top: 1rem;
}

.markdown-content dd {
  margin-inline-start: 1.5rem;
  margin-bottom: 0.5rem;
  padding-inline-start: 1rem;
  border-inline-start: 2px solid #ccfbf1;
}

/* Math */
.markdown-content .math {
  direction: ltr;
  text-align: left;
}

/* Emoji */
.markdown-content .emoji {
  font-style: normal;
}

/* Dark Mode Styles */
html.dark .markdown-content {
  color: #e5e7eb;
}

html.dark .markdown-content h1,
html.dark .markdown-content h2,
html.dark .markdown-content h3,
html.dark .markdown-content h4,
html.dark .markdown-content h5,
html.dark .markdown-content h6 {
  color: #2dd4bf; /* teal-400 */
  border-bottom-color: #14b8a6; /* teal-500 */
}

html.dark .markdown-content h6 {
  color: #9ca3af;
}

html.dark .markdown-content strong,
html.dark .markdown-content b {
  color: #99f6e4; /* teal-200 */
}

html.dark .markdown-content em,
html.dark .markdown-content i {
  color: #fbbf24; /* amber-400 */
}

html.dark .markdown-content del,
html.dark .markdown-content s {
  color: #6b7280;
}

html.dark .markdown-content a { 
  color: #7dd3fc; /* sky-300 */ 
}

html.dark .markdown-content a:hover { 
  color: #e0f2fe; /* sky-100 */
  background-color: #0c4a6e; /* sky-900 */
}

html.dark .markdown-content a.citation-link {
  background-color: #134e4a; /* teal-900 */
  color: #99f6e4; /* teal-200 */
  border-color: #0f766e; /* teal-700 */
}

html.dark .markdown-content a.citation-link:hover {
  background-color: #0f766e; /* teal-700 */
  color: #f0fdfa; /* teal-50 */
}

html.dark .markdown-content ul > li::before {
  color: #2dd4bf; /* teal-400 */
}

html.dark .markdown-content ol > li::before {
  background-color: #134e4a; /* teal-900 */
  color: #99f6e4; /* teal-200 */
}

html.dark .markdown-content code {
  background-color: #374151; /* gray-700 */
  color: #fda4af; /* rose-300 */
}

html.dark .markdown-content pre {
  background-color: #1f2937; /* gray-800 */
  border-color: #4b5563; /* gray-600 */
}

html.dark .markdown-content pre code { 
  color: #f9fafb; /* gray-50 */ 
}

html.dark .markdown-content blockquote {
  border-inline-start-color: #2dd4bf; /* teal-400 */
  background-color: rgba(19, 78, 74, 0.2); /* teal-900 with 20% opacity */
  color: #ccfbf1; /* teal-100 */
}

html.dark .markdown-content table {
  border-color: #4b5563; /* gray-600 */
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.4);
}

html.dark .markdown-content th,
html.dark .markdown-content td {
  border-bottom-color: #4b5563; /* gray-600 */
}

html.dark .markdown-content th {
  background-color: #115e59; /* teal-800 */
  border-bottom-color: #0d9488; /* teal-600 */
}

html.dark .markdown-content tr:nth-child(even) {
  background-color: #111827; /* gray-900 */
}

html.dark .markdown-content tr:hover {
  background-color: #134e4a; /* teal-900 */
}

html.dark .markdown-content td:first-child {
  color: #5eead4; /* teal-300 */
  border-inline-end-color: #4b5563;
}

html.dark .markdown-content hr {
  border-top-color: #4b5563; /* gray-600 */
}

html.dark .markdown-content img {
  filter: brightness(0.9);
}

html.dark .markdown-content kbd {
  background-color: #374151;
  border-color: #4b5563;
  color: #e5e7eb;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}

html.dark .markdown-content mark {
  background-color: #78350f; /* amber-900 */
  color: #fef3c7; /* amber-100 */
}

html.dark .markdown-content .footnotes {
  border-top-color: #4b5563;
}

html.dark .markdown-content dd {
  border-inline-start-color: #0f766e;
}

/* Responsive Design */
@media (max-width: 768px) {
  .markdown-content {
    font-size: 0.95rem;
  }
  
  .markdown-content h1 { font-size: 1.75rem; }
  .markdown-content h2 { font-size: 1.5rem; }
  .markdown-content h3 { font-size: 1.25rem; }
  
  .markdown-content table {
    display: block;
    overflow-x: auto;
  }
  
  .markdown-content pre {
    padding: 1rem;
    font-size: 0.875rem;
  }
}