/**
 * MDXEditor Custom Theme
 * Integrates with ThrillWiki's design system using semantic HSL tokens
 */

.mdxeditor {
  /* Base colors - light mode */
  --baseBase: hsl(var(--background));
  --baseBgSubtle: hsl(var(--muted));
  --baseBg: hsl(var(--muted) / 0.5);
  --baseBgHover: hsl(var(--muted) / 0.8);
  --baseBgActive: hsl(var(--muted));
  --baseLine: hsl(var(--border) / 0.3);
  --baseBorder: hsl(var(--border));
  --baseBorderHover: hsl(var(--border) / 0.8);
  --baseSolid: hsl(var(--muted-foreground));
  --baseSolidHover: hsl(var(--foreground) / 0.8);
  --baseText: hsl(var(--foreground));
  --baseTextContrast: hsl(var(--foreground));

  /* Accent colors - primary purple/blue */
  --accentBase: hsl(var(--primary) / 0.1);
  --accentBgSubtle: hsl(var(--primary) / 0.15);
  --accentBg: hsl(var(--primary) / 0.2);
  --accentBgHover: hsl(var(--primary) / 0.3);
  --accentBgActive: hsl(var(--primary) / 0.4);
  --accentLine: hsl(var(--primary) / 0.5);
  --accentBorder: hsl(var(--primary) / 0.6);
  --accentBorderHover: hsl(var(--primary) / 0.8);
  --accentSolid: hsl(var(--primary));
  --accentSolidHover: hsl(var(--primary) / 0.9);
  --accentText: hsl(var(--primary));
  --accentTextContrast: hsl(var(--primary-foreground));

  /* Font configuration */
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Page background */
  --basePageBg: hsl(var(--background));
  background: var(--basePageBg);
  color: var(--baseText);
}

/* Dark mode theme */
.mdxeditor.dark-theme {
  /* Base colors - dark mode */
  --baseBase: hsl(var(--background));
  --baseBgSubtle: hsl(var(--muted));
  --baseBg: hsl(var(--muted) / 0.3);
  --baseBgHover: hsl(var(--muted) / 0.5);
  --baseBgActive: hsl(var(--muted) / 0.7);
  --baseLine: hsl(var(--border) / 0.3);
  --baseBorder: hsl(var(--border));
  --baseBorderHover: hsl(var(--border) / 0.8);
  --baseSolid: hsl(var(--muted-foreground));
  --baseSolidHover: hsl(var(--foreground) / 0.8);
  --baseText: hsl(var(--foreground));
  --baseTextContrast: hsl(var(--foreground));

  /* Accent colors remain consistent but adapt to dark bg */
  --accentBase: hsl(var(--primary) / 0.15);
  --accentBgSubtle: hsl(var(--primary) / 0.2);
  --accentBg: hsl(var(--primary) / 0.25);
  --accentBgHover: hsl(var(--primary) / 0.35);
  --accentBgActive: hsl(var(--primary) / 0.45);
  --accentLine: hsl(var(--primary) / 0.5);
  --accentBorder: hsl(var(--primary) / 0.7);
  --accentBorderHover: hsl(var(--primary) / 0.9);
  --accentSolid: hsl(var(--primary));
  --accentSolidHover: hsl(var(--primary) / 0.85);
  --accentText: hsl(var(--primary));
  --accentTextContrast: hsl(var(--primary-foreground));

  /* Page background */
  --basePageBg: hsl(var(--background));
}

/* Popup container z-index override */
.mdxeditor-popup-container {
  z-index: 9999;
}

/* Content area styling */
.mdx-content-area {
  font-family: inherit;
  line-height: 1.75;
}

.mdx-content-area h1,
.mdx-content-area h2,
.mdx-content-area h3,
.mdx-content-area h4,
.mdx-content-area h5,
.mdx-content-area h6 {
  font-weight: 600;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  color: hsl(var(--foreground));
}

.mdx-content-area a {
  color: hsl(var(--primary));
  text-decoration: underline;
  text-decoration-color: hsl(var(--primary) / 0.3);
  transition: text-decoration-color 0.2s;
}

.mdx-content-area a:hover {
  text-decoration-color: hsl(var(--primary));
}

.mdx-content-area code {
  background: hsl(var(--muted));
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  font-size: 0.875em;
  font-family: var(--font-mono);
}

.mdx-content-area pre {
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  padding: 1rem;
  overflow-x: auto;
}

.mdx-content-area pre code {
  background: transparent;
  padding: 0;
}

.mdx-content-area blockquote {
  border-left: 4px solid hsl(var(--primary));
  padding-left: 1rem;
  color: hsl(var(--muted-foreground));
  font-style: italic;
}

.mdx-content-area table {
  border-collapse: collapse;
  width: 100%;
}

.mdx-content-area table th,
.mdx-content-area table td {
  border: 1px solid hsl(var(--border));
  padding: 0.5rem;
}

.mdx-content-area table th {
  background: hsl(var(--muted));
  font-weight: 600;
}

/* Toolbar button styling */
.mdxeditor-toolbar button {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 0.375rem;
}

.mdxeditor-toolbar button:hover {
  background: hsl(var(--primary) / 0.1);
  color: hsl(var(--primary));
}

.mdxeditor-toolbar button[data-active="true"],
.mdxeditor-toolbar button[aria-pressed="true"] {
  background: hsl(var(--primary) / 0.15);
  color: hsl(var(--primary));
  font-weight: 500;
}

/* Toolbar separator */
.mdxeditor-toolbar [role="separator"] {
  background: hsl(var(--border));
  width: 1px;
  height: 1.5rem;
  margin: 0 0.5rem;
}

/* Dialog styling */
.mdxeditor [role="dialog"] {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  box-shadow: 0 10px 40px -10px hsl(var(--foreground) / 0.1);
  padding: 1.5rem;
}

.mdxeditor [role="dialog"] h2,
.mdxeditor [role="dialog"] h3 {
  color: hsl(var(--foreground));
  margin-bottom: 1rem;
}

.mdxeditor [role="dialog"] label {
  color: hsl(var(--foreground));
  font-weight: 500;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  display: block;
}

.mdxeditor [role="dialog"] input[type="text"],
.mdxeditor [role="dialog"] input[type="url"],
.mdxeditor [role="dialog"] textarea {
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  color: hsl(var(--foreground));
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  width: 100%;
  font-size: 0.875rem;
  transition: all 0.2s;
}

.mdxeditor [role="dialog"] input:focus,
.mdxeditor [role="dialog"] textarea:focus {
  outline: none;
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 3px hsl(var(--primary) / 0.1);
}

.mdxeditor [role="dialog"] button {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-weight: 500;
  transition: all 0.2s;
  border: none;
  cursor: pointer;
}

.mdxeditor [role="dialog"] button:hover {
  background: hsl(var(--primary) / 0.9);
}

.mdxeditor [role="dialog"] button[data-variant="secondary"] {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

.mdxeditor [role="dialog"] button[data-variant="secondary"]:hover {
  background: hsl(var(--secondary) / 0.9);
}

/* Select and dropdown styling */
.mdxeditor-select-trigger {
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  color: hsl(var(--foreground));
  padding: 0.375rem 0.75rem;
  border-radius: 0.375rem;
  transition: all 0.2s;
}

.mdxeditor-select-trigger:hover {
  background: hsl(var(--accent) / 0.05);
  border-color: hsl(var(--primary) / 0.5);
}

.mdxeditor-select-content {
  background: hsl(var(--popover));
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  box-shadow: 0 10px 40px -10px hsl(var(--foreground) / 0.15);
  max-height: 50vh;
  overflow-y: auto;
  padding: 0.25rem;
  z-index: 9999;
}

.mdxeditor-select-item {
  padding: 0.5rem 0.75rem;
  border-radius: 0.25rem;
  cursor: pointer;
  transition: all 0.15s;
  color: hsl(var(--foreground));
}

.mdxeditor-select-item:hover {
  background: hsl(var(--primary) / 0.1);
  color: hsl(var(--primary));
}

.mdxeditor-select-item[data-selected="true"] {
  background: hsl(var(--primary) / 0.15);
  color: hsl(var(--primary));
  font-weight: 500;
}

/* Image styling */
.mdxeditor img {
  border-radius: 0.375rem;
  border: 1px solid hsl(var(--border) / 0.3);
  max-width: 100%;
  height: auto;
}

.mdxeditor img:hover {
  border-color: hsl(var(--primary) / 0.5);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .mdxeditor-toolbar {
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem;
  }

  .mdxeditor-toolbar button {
    min-width: 2rem;
    min-height: 2rem;
  }

  .mdxeditor-select-content {
    max-height: 40vh;
  }

  .mdxeditor [role="dialog"] {
    max-width: 90vw;
    padding: 1rem;
  }
}
