/* Docizr Site Styles - Enhanced with Design System
 * 
 * This file now serves as the main entry point for all styling,
 * importing the comprehensive design system and maintaining
 * backward compatibility with existing components.
 * 
 * The design system provides:
 * - Consistent design tokens (colors, spacing, typography)
 * - Reusable component library
 * - Utility classes for rapid development
 * - Responsive design patterns
 * - Accessibility enhancements
 * - Performance optimizations
 */

/* ========================================================================
   DESIGN SYSTEM IMPORT
   Comprehensive CSS architecture for consistent styling
   ======================================================================== */
@import 'design-system/index.css';

/* ========================================================================
   PREVIEW PANE THEMES
   Theme application for persistent preview containers
   ======================================================================== */
@import 'preview-pane-themes.css';

/* ========================================================================
   EDITOR COMPONENTS
   Specialized styles for editor components
   ======================================================================== */
@import 'editors/code-editor-splitter.css';

/* ========================================================================
   DOCIZR-SPECIFIC CUSTOMIZATIONS
   Application-specific styles that extend the design system
   ======================================================================== */

/* Global application wrapper */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--dz-bg-secondary);
  font-family: var(--dz-font-sans);
}

/* Main content area */
main {
  flex: 1;
  background-color: var(--dz-bg-secondary);
}

/* Content wrapper */
.content {
  padding: 0 var(--dz-space-4);
  background-color: var(--dz-bg-secondary);
}

/* Container enhancement */
.container {
  background-color: var(--dz-bg-secondary);
}

/* ========================================================================
   THEME SYSTEM ENHANCEMENTS
   Improved theme switching with design system tokens
   ======================================================================== */

/* Theme toggle button enhancement */
.theme-toggle {
  background: none;
  border: 1px solid var(--dz-border-primary);
  color: var(--dz-text-primary);
  padding: var(--dz-space-2) var(--dz-space-3);
  border-radius: var(--dz-radius-md);
  cursor: pointer;
  transition: var(--dz-transition-colors);
  font-family: var(--dz-font-sans);
  font-size: var(--dz-font-size-sm);
}

.theme-toggle:hover {
  background-color: var(--dz-bg-tertiary);
  border-color: var(--dz-border-secondary);
}

.theme-toggle:focus-visible {
  outline: var(--dz-focus-ring-width) solid var(--dz-focus-ring-color);
  outline-offset: var(--dz-focus-ring-offset);
}

/* ========================================================================
   ERROR HANDLING & STATUS MESSAGES
   Enhanced error UI with design system components
   ======================================================================== */

/* Blazor error UI enhancement */
#blazor-error-ui {
  background: var(--dz-warning-light);
  border-top: 1px solid var(--dz-warning-base);
  bottom: 0;
  box-shadow: var(--dz-shadow-lg);
  display: none;
  left: 0;
  padding: var(--dz-space-3) var(--dz-space-5);
  position: fixed;
  width: 100%;
  z-index: var(--dz-z-notification);
  color: var(--dz-warning-dark);
  font-family: var(--dz-font-sans);
  font-size: var(--dz-font-size-sm);
}

#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: var(--dz-space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--dz-warning-dark);
  padding: var(--dz-space-1);
  border-radius: var(--dz-radius-sm);
  transition: var(--dz-transition-colors);
}

#blazor-error-ui .dismiss:hover {
  background-color: var(--dz-warning-base);
}

#blazor-error-ui .btn-close {
  background-color: transparent;
  border: none;
  color: var(--dz-warning-dark);
  cursor: pointer;
  font-size: var(--dz-font-size-lg);
  padding: var(--dz-space-1) var(--dz-space-2);
  border-radius: var(--dz-radius-sm);
  transition: var(--dz-transition-colors);
}

#blazor-error-ui .btn-close:hover {
  background-color: var(--dz-warning-base);
}

/* ========================================================================
   ENHANCED TYPOGRAPHY
   Unicode support and font optimizations
   ======================================================================== */

/* Enhanced font stack for markdown content */
.markdown-content, 
.markdown-preview, 
.raw-content, 
.preview-content,
.mermaid-preview, 
.document-content, 
.file-content {
  font-family: var(--dz-font-sans);
  font-variant-emoji: emoji;
  text-rendering: optimizeLegibility;
  line-height: var(--dz-line-height-relaxed);
}

/* Mathematical content styling (DEFAULT - keeps rounded corners for marketing/canvas editor) */
.math-container {
  margin: var(--dz-space-4) 0;
  text-align: center;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: var(--dz-radius-md);
  /* FIXED: Use transparent background to inherit from preview pane theme */
  background: transparent !important;
  background-color: transparent !important;
  padding: var(--dz-space-2);
}

/* CODE EDITOR - Sharp corners for math containers to maximize viewing area */
.code-editor .math-container {
  /* SHARP CORNERS: Remove border radius for maximized content viewing */
  border-radius: 0 !important;
  /* REDUCED PADDING: Less visual bulk, more content */
  padding: var(--dz-space-1) !important;
  /* REDUCED MARGIN: Tighter spacing for more content density */
  margin: var(--dz-space-2) 0 !important;
}

.math-container .math-content {
  display: inline-block;
  max-width: 100%;
  font-family: var(--dz-font-serif);
}

/* CRITICAL FIX: Ensure inline math stays inline and doesn't create new lines */
.math-inline {
  display: inline !important;
  vertical-align: baseline !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* CRITICAL FIX: Force MathJax SVG containers inside inline math to be inline */
.math-inline mjx-container,
.math-inline mjx-container[display="true"],
.math-inline .MathJax,
.math-inline .MathJax_Display {
  display: inline !important;
  vertical-align: middle !important;
  margin: 0 0.1em !important; /* REDUCED: Tighter spacing around inline math */
  padding: 0 !important;
}

/* Ensure all MathJax inline elements stay inline */
mjx-container:not([display="true"]) {
  display: inline !important;
  vertical-align: middle !important;
  padding: 0 0.1em !important; /* REDUCED: Tighter spacing */
}

.math-display {
  display: block;
  text-align: center;
  margin: var(--dz-space-4) 0;
}

/* CODE EDITOR - Reduce math display margins for more content density */
.code-editor .math-display {
  margin: var(--dz-space-2) 0 !important;
}

/* Math error styling (DEFAULT - keeps rounded corners) */
.math-error {
  border-left: 4px solid var(--dz-warning-base);
  padding-left: var(--dz-space-4);
  background-color: var(--dz-warning-light);
  border-radius: var(--dz-radius-md);
  margin: var(--dz-space-4) 0;
}

/* CODE EDITOR - Sharp corners for math errors */
.code-editor .math-error {
  /* SHARP CORNERS: Remove border radius */
  border-radius: 0 !important;
  /* REDUCED SPACING: More compact error display */
  padding-left: var(--dz-space-2) !important;
  margin: var(--dz-space-2) 0 !important;
}

.math-error .alert {
  margin-bottom: 0;
  background: transparent;
  border: none;
  padding: var(--dz-space-2) 0;
}

/* MathJax styling adjustments */
.MathJax {
  color: var(--dz-text-primary) !important;
}

.MathJax_Display {
  margin: var(--dz-space-4) 0 !important;
}

/* CODE EDITOR - Tighter MathJax spacing */
.code-editor .MathJax_Display {
  margin: var(--dz-space-2) 0 !important;
}

/* ========================================================================
   INTERACTIVE DIAGRAM NOTIFICATIONS
   Enhanced notification system for diagram interactions
   ======================================================================== */

.diagram-click-notification {
  font-family: var(--dz-font-sans);
  background: linear-gradient(135deg, var(--dz-bg-accent) 0%, var(--dz-brand-primary-hover) 100%);
  color: var(--dz-text-inverse);
  padding: var(--dz-space-3) var(--dz-space-4);
  border-radius: var(--dz-radius-lg);
  box-shadow: var(--dz-shadow-lg);
  user-select: none;
  cursor: pointer;
  animation: slideInRight 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  font-size: var(--dz-font-size-sm);
  font-weight: var(--dz-font-weight-medium);
}

.diagram-click-notification:hover {
  transform: translateX(0) scale(1.02) !important;
  box-shadow: var(--dz-shadow-xl) !important;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%) scale(0.8);
    opacity: 0;
  }
  to {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

/* ========================================================================
   MONACO EDITOR ENHANCEMENTS
   Professional code editor styling with design system integration
   ======================================================================== */

/* DEFAULT Monaco editor styling (preserves rounded corners for canvas editor, etc.) */
.monaco-professional-editor .monaco-editor-container {
  border: 1px solid var(--dz-border-primary);
  border-radius: var(--dz-radius-lg);
  overflow: hidden;
  transition: var(--dz-transition-colors);
  background-color: var(--dz-bg-primary);
}

.monaco-professional-editor .monaco-editor-container:focus-within {
  border-color: var(--dz-border-focus);
  box-shadow: 0 0 0 3px var(--dz-focus-ring-color);
}

/* CODE EDITOR specific overrides - SHARP CORNERS & MAXIMUM WORKING AREA */
.code-editor .monaco-professional-editor .monaco-editor-container,
.code-editor .monaco-editor-container {
  /* SHARP CORNERS: Remove all border radius for maximum editor space */
  border-radius: 0 !important;
  /* Remove borders that waste precious editor space */
  border: none !important;
  /* Remove any focus styling that adds visual bulk */
  box-shadow: none !important;
  /* Ensure full area utilization */
  padding: 0 !important;
  margin: 0 !important;
}

/* Enhanced Monaco Editor font rendering (applies to all Monaco instances) */
.docizr-monaco-editor {
  font-variant-ligatures: contextual;
  font-feature-settings: 'liga' 1, 'calt' 1;
  text-rendering: optimizeLegibility;
  font-family: var(--dz-font-mono);
}

.docizr-monaco-editor .monaco-editor {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* CODE EDITOR Monaco - ensure no padding/margin waste */
.code-editor .docizr-monaco-editor,
.code-editor .monaco-editor {
  /* Remove any inherited padding that reduces editor area */
  padding: 0 !important;
  margin: 0 !important;
  /* SHARP CORNERS: Ensure editor content itself has no rounded corners */
  border-radius: 0 !important;
}

/* Font preview styling (used in panels, keep rounded corners) */
.font-preview {
  padding: var(--dz-space-3);
  border: 1px solid var(--dz-border-primary);
  border-radius: var(--dz-radius-md);
  margin-top: var(--dz-space-2);
  background-color: var(--dz-bg-primary);
  color: var(--dz-text-primary);
  font-size: var(--dz-font-size-sm);
  line-height: var(--dz-line-height-normal);
  font-family: var(--dz-font-mono);
  transition: var(--dz-transition-colors);
}

/* Font-specific preview classes */
.font-preview-fira-code { font-family: 'Fira Code', var(--dz-font-mono); }
.font-preview-cascadia-code { font-family: 'Cascadia Code', var(--dz-font-mono); }
.font-preview-jetbrains-mono { font-family: 'JetBrains Mono', var(--dz-font-mono); }
.font-preview-source-code-pro { font-family: 'Source Code Pro', var(--dz-font-mono); }
.font-preview-roboto-mono { font-family: 'Roboto Mono', var(--dz-font-mono); }
.font-preview-consolas { font-family: 'Consolas', var(--dz-font-mono); }
.font-preview-monaco { font-family: 'Monaco', var(--dz-font-mono); }
.font-preview-auto { font-family: var(--dz-font-mono); }

/* ========================================================================
   RESPONSIVE DESIGN ENHANCEMENTS
   Mobile-first responsive design with design system breakpoints
   ======================================================================== */

/* Mobile optimizations */
@media (max-width: 767.98px) {
  .content {
    padding: 0 var(--dz-space-2);
  }
  
  .diagram-click-notification {
    top: 100px !important;
    right: var(--dz-space-2) !important;
    left: var(--dz-space-2) !important;
    max-width: none !important;
    font-size: var(--dz-font-size-xs) !important;
  }
  
  .math-container {
    font-size: 0.9rem;
    padding: var(--dz-space-1);
  }
  
  .MathJax {
    font-size: 0.9em !important;
  }
}

/* Tablet optimizations */
@media (min-width: 768px) and (max-width: 991.98px) {
  .content {
    padding: 0 var(--dz-space-3);
  }
}

/* Desktop optimizations */
@media (min-width: 992px) {
  .content {
    padding: 0 var(--dz-space-6);
  }
}

/* ========================================================================
   ACCESSIBILITY IMPROVEMENTS
   Enhanced accessibility with design system patterns
   ======================================================================== */

/* Enhanced focus management */
.dz-skip-to-main {
  position: absolute;
  top: -100px;
  left: var(--dz-space-4);
  background: var(--dz-bg-accent);
  color: var(--dz-text-inverse);
  padding: var(--dz-space-2) var(--dz-space-4);
  border-radius: var(--dz-radius-md);
  text-decoration: none;
  z-index: var(--dz-z-tooltip);
  transition: top var(--dz-duration-150) var(--dz-ease-out);
  font-family: var(--dz-font-sans);
  font-size: var(--dz-font-size-sm);
  font-weight: var(--dz-font-weight-medium);
}

.dz-skip-to-main:focus {
  top: var(--dz-space-4);
}

/* High contrast mode enhancements */
@media (prefers-contrast: high) {
  .diagram-click-notification {
    border: 2px solid var(--dz-text-inverse);
  }
  
  .monaco-editor-container {
    border-width: 2px;
  }
  
  .font-preview {
    border-width: 2px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .diagram-click-notification {
    animation: none;
    transition: none;
  }
  
  .monaco-editor-container {
    transition: none;
  }
  
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ========================================================================
   PERFORMANCE OPTIMIZATIONS
   CSS optimizations for better rendering performance
   ======================================================================== */

/* Disable transitions during page load */
.preload * {
  transition: none !important;
}

/* GPU acceleration for smooth scrolling */
.smooth-scroll {
  transform: translateZ(0);
  will-change: scroll-position;
}

/* Optimize font loading */
@font-face {
  font-display: swap;
}

/* ========================================================================
   PRINT STYLES
   Optimized print layout with design system
   ======================================================================== */

@media print {
  .theme-toggle,
  .diagram-click-notification,
  #blazor-error-ui {
    display: none !important;
  }
  
  .page {
    background: white !important;
    color: black !important;
  }
  
  .content {
    padding: 0 !important;
  }
  
  .monaco-editor-container {
    border: 1px solid #000 !important;
    background: white !important;
  }
  
  .math-container {
    background: white !important;
    border: 1px solid #000 !important;
  }
}

/* ========================================================================
   LEGACY COMPATIBILITY
   Maintain compatibility with existing component styles
   ======================================================================== */

/* Top row legacy support */
.top-row {
  background-color: var(--dz-navbar-bg);
  color: var(--dz-navbar-text);
  padding: var(--dz-space-4);
  margin-bottom: var(--dz-space-8);
  transition: var(--dz-transition-colors);
}

.top-row h1 {
  margin: 0;
  font-size: var(--dz-font-size-2xl);
  font-weight: var(--dz-font-weight-light);
  color: var(--dz-navbar-text);
}

.top-row p {
  margin: 0;
  opacity: 0.8;
  color: var(--dz-navbar-text);
}

/* Utility class migration */
.border { border-color: var(--dz-border-primary) !important; }
.text-muted { color: var(--dz-text-muted) !important; }
.text-primary { color: var(--dz-text-accent) !important; }
.bg-light { background-color: var(--dz-bg-secondary) !important; }

/* Spinner enhancement */
.spinner-border {
  color: var(--dz-bg-accent);
  border-width: 2px;
  border-top-color: var(--dz-bg-accent);
  border-right-color: transparent;
  border-bottom-color: transparent;
  border-left-color: transparent;
}

/* ========================================================================
   LOADING OVERLAY SYSTEM
   Full-screen loading overlays for file operations and async tasks
   ======================================================================== */

/* Main loading overlay that covers the entire editor */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--dz-z-modal);
  animation: fadeInOverlay 0.2s ease-out;
}

@keyframes fadeInOverlay {
  from {
    opacity: 0;
    backdrop-filter: blur(0px);
  }
  to {
    opacity: 1;
    backdrop-filter: blur(4px);
  }
}

/* Loading content container */
.loading-content {
  background: var(--dz-bg-primary);
  border: 1px solid var(--dz-border-primary);
  border-radius: var(--dz-radius-lg);
  padding: var(--dz-space-6) var(--dz-space-8);
  box-shadow: var(--dz-shadow-xl);
  display: flex;
  align-items: center;
  gap: var(--dz-space-4);
  min-width: 300px;
  animation: slideInScale 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideInScale {
  from {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Loading text styling */
.loading-text {
  color: var(--dz-text-primary);
  font-family: var(--dz-font-sans);
  font-size: var(--dz-font-size-lg);
  font-weight: var(--dz-font-weight-medium);
  line-height: var(--dz-line-height-normal);
}

/* Enhanced spinner animation for better visual feedback */
.loading-overlay .spinner-border {
  width: 2.5rem;
  height: 2.5rem;
  border-width: 3px;
  color: var(--dz-brand-primary-base);
  border-top-color: var(--dz-brand-primary-base);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Responsive loading overlay */
@media (max-width: 767.98px) {
  .loading-content {
    margin: var(--dz-space-4);
    padding: var(--dz-space-4) var(--dz-space-6);
    min-width: auto;
    max-width: calc(100vw - var(--dz-space-8));
  }
  
  .loading-text {
    font-size: var(--dz-font-size-base);
  }
  
  .loading-overlay .spinner-border {
    width: 2rem;
    height: 2rem;
    border-width: 2px;
  }
}

/* Dark theme adjustments for loading overlay */
[data-theme="dark"] .loading-overlay {
  background-color: rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .loading-content {
  background: var(--dz-bg-primary);
  border-color: var(--dz-border-primary);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
}

/* High contrast mode for loading overlay */
@media (prefers-contrast: high) {
  .loading-overlay {
    background-color: rgba(0, 0, 0, 0.8);
  }
  
  .loading-content {
    border-width: 2px;
    border-color: var(--dz-border-focus);
  }
  
  .loading-overlay .spinner-border {
    border-width: 4px;
  }
}

/* Reduced motion support for loading overlay */
@media (prefers-reduced-motion: reduce) {
  .loading-overlay {
    animation: none;
    backdrop-filter: none;
    background-color: rgba(0, 0, 0, 0.5);
  }
  
  .loading-content {
    animation: none;
    transform: none;
  }
  
  .loading-overlay .spinner-border {
    animation: none;
    border-top-color: var(--dz-brand-primary-base);
    border-right-color: var(--dz-brand-primary-base);
    border-bottom-color: var(--dz-brand-primary-base);
    border-left-color: var(--dz-brand-primary-base);
  }
  
  .loading-overlay .spinner-border::before {
    content: '?';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5em;
    color: var(--dz-brand-primary-base);
  }
}

/* ========================================================================
   FUTURE-PROOFING
   Preparation for future design system enhancements
   ======================================================================== */

/* CSS custom property polyfill support */
@supports not (--custom: property) {
  .fallback-colors {
    background-color: #ffffff;
    color: #212529;
    border-color: #dee2e6;
  }
}

/* Modern CSS features with fallbacks */
@supports (backdrop-filter: blur(10px)) {
  .diagram-click-notification {
    backdrop-filter: blur(10px);
  }
}

/* Grid layout fallbacks */
@supports not (display: grid) {
  .grid-fallback {
    display: flex;
    flex-wrap: wrap;
  }
}

/* ========================================================================
   DESIGN SYSTEM VALIDATION
   Development-only styles for design system validation
   ======================================================================== */

/* Design system status indicator */
body {
  --dz-design-system-version: "1.0.0";
  --dz-design-system-status: "active";
}

/* Development mode helper */
@media (max-width: 0px) {
  .dz-debug-info::after {
    content: "Design System v" var(--dz-design-system-version) " - " var(--dz-design-system-status);
    position: fixed;
    bottom: 0;
    right: 0;
    background: var(--dz-success-base);
    color: var(--dz-text-inverse);
    padding: var(--dz-space-1) var(--dz-space-2);
    font-size: var(--dz-font-size-xs);
    z-index: var(--dz-z-tooltip);
  }
}

/* Core tokens for consistent spacing and layout */
:root {
    /* ... existing variables ... */
    
    /* Math rendering styles */
    --dz-math-font-family: 'Noto Sans Math', 'Latin Modern Math', 'STIX Two Math', 'Times New Roman', serif;
    --dz-math-inline-padding: 0.125rem 0.25rem;
    --dz-math-display-padding: 1rem 0;
    --dz-math-fallback-bg: rgba(255, 235, 59, 0.1);
    --dz-math-fallback-border: 1px dashed rgba(255, 193, 7, 0.5);
}

/* Math rendering support */
.math-fallback {
    font-family: var(--dz-math-font-family);
    background: var(--dz-math-fallback-bg);
    border: var(--dz-math-fallback-border);
    border-radius: var(--dz-radius-base);
    padding: var(--dz-math-inline-padding);
    font-style: italic;
    color: var(--dz-text-secondary);
}

.math-fallback.display-math {
    display: block;
    text-align: center;
    padding: var(--dz-math-display-padding);
    margin: var(--dz-space-4) 0;
}

.math-fallback.inline-math {
    display: inline;
    padding: var(--dz-math-inline-padding);
}

/* MathJax container styling */
mjx-container {
    margin: var(--dz-space-2) 0;
}

mjx-container[display="true"] {
    text-align: center;
    margin: var(--dz-space-4) 0;
}

.MathJax_Display {
    text-align: center;
    margin: var(--dz-space-4) 0;
}

/* Dark theme math adjustments */
[data-theme="dark"] .math-fallback {
    --dz-math-fallback-bg: rgba(255, 235, 59, 0.05);
    --dz-math-fallback-border: 1px dashed rgba(255, 193, 7, 0.3);
    color: var(--dz-text-muted);
}
