/*
  Theme tokens inspired by shadcn/ui (no Tailwind required).
  We expose semantic color tokens for light and dark themes.
*/
:root {
  /* Light theme (default) */
  --background: 0 0% 100%; /* white */
  --foreground: 222.2 84% 4.9%; /* slate-900 */

  --card: 0 0% 100%;
  --card-foreground: 222.2 84% 4.9%;

  --popover: 0 0% 100%;
  --popover-foreground: 222.2 84% 4.9%;

  --primary: 222.2 47.4% 11.2%;
  --primary-foreground: 210 40% 98%;

  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;

  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;

  --accent: 210 40% 96.1%;
  --accent-foreground: 222.2 47.4% 11.2%;

  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 210 40% 98%;

  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
  --ring: 222.2 84% 4.9%;

  --radius: 0.5rem;
  --shadow: 0 4px 10px rgba(0,0,0,0.08);
  --transition: all 0.2s ease;

  /* Legacy tokens bridge */
  --primary-color: hsl(var(--primary));
  --secondary-color: hsl(175 61% 55%); /* teal-ish accent for CTA */
}

.dark {
  /* Dark theme */
  --background: 222.2 84% 4.9%;
  --foreground: 210 40% 98%;

  --card: 222.2 84% 4.9%;
  --card-foreground: 210 40% 98%;

  --popover: 222.2 84% 4.9%;
  --popover-foreground: 210 40% 98%;

  --primary: 210 40% 98%;
  --primary-foreground: 222.2 47.4% 11.2%;

  --secondary: 217.2 32.6% 17.5%;
  --secondary-foreground: 210 40% 98%;

  --muted: 217.2 32.6% 17.5%;
  --muted-foreground: 215 20.2% 65.1%;

  --accent: 217.2 32.6% 17.5%;
  --accent-foreground: 210 40% 98%;

  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 210 40% 98%;

  --border: 217.2 32.6% 17.5%;
  --input: 217.2 32.6% 17.5%;
  --ring: 212.7 26.8% 83.9%;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  line-height: 1.6;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Full width container for editor and viewer pages */
.container-full {
  width: 100%;
  margin: 0 auto;
  padding: 0 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
  font-size: 1rem;
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.btn:hover {
  background: hsl(var(--accent)) brightness(0.95);
  transform: translateY(-1px);
  border-color: hsl(var(--ring));
}

.btn-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: hsl(var(--primary));
}

.btn-primary:hover {
  background: hsl(var(--primary)) brightness(0.9);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  color: hsl(var(--primary-foreground));
}

/* Ensure proper contrast for btn-primary text in both themes */
:root .btn-primary {
  color: white; /* White text on dark primary background in light mode */
}

.dark .btn-primary {
  color: black; /* Black text on light primary background in dark mode */
}

.btn-secondary {
  background: var(--secondary-color);
  color: white;
  border-color: var(--secondary-color);
}

.btn-secondary:hover {
  background: color-mix(in hsl, var(--secondary-color) 90%, black);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
}

.grid {
  display: grid;
  gap: 2rem;
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

h1, h2, h3, h4, h5, h6 {
  margin-bottom: 1rem;
  font-weight: 700;
  color: hsl(var(--foreground));
}

h1 {
  font-size: 2.5rem;
}

h2 {
  font-size: 2rem;
}

h3 {
  font-size: 1.5rem;
}

p {
  margin-bottom: 1rem;
  color: hsl(var(--muted-foreground));
}

.text-center {
  text-align: center;
}

.mb-4 {
  margin-bottom: 2rem;
}

.mb-8 {
  margin-bottom: 4rem;
}

@media (max-width: 768px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  
  h1 {
    font-size: 2rem;
  }
  
  h2 {
    font-size: 1.5rem;
  }
}

/* Navbar styles leveraging tokens */
.navbar {
  background: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border));
  position: sticky;
  top: 0;
  z-index: 1000;
}

.nav-link {
  color: hsl(var(--muted-foreground));
}
.nav-link.active {
  color: var(--secondary-color);
  background: color-mix(in hsl, var(--secondary-color) 20%, transparent);
}

/* Inputs */
input, textarea, select {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
}
textarea { width: 100%; }

/* Code and pre elements */
code {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.875rem;
  border: 1px solid hsl(var(--border));
}

/* Darker background for code in light mode */
:root code {
  background: hsl(220 14% 96%); /* Light gray background for better contrast */
}

.dark code {
  background: hsl(var(--muted)); /* Use default dark theme muted color */
}

pre {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  border: 1px solid hsl(var(--border));
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.875rem;
  line-height: 1.5;
}

pre code {
  background: transparent;
  border: none;
  padding: 0;
}

/* Light mode text fixes */
:root {
  /* Ensure better contrast in light mode */
  --muted-foreground: 215.4 16.3% 46.9%; /* Darker for better readability */
}

.dark {
  /* Dark mode keeps existing values */
  --muted-foreground: 215 20.2% 65.1%;
}

/* Utility */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.rounded { border-radius: var(--radius); }
.w-100 { width: 100%; }
.text-muted { color: hsl(var(--muted-foreground)); }
.text-accent { color: var(--secondary-color); }

/* Enhanced button contrast for light mode */
.btn:focus {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

/* Ensure good readability for all text elements */
label {
  color: hsl(var(--foreground));
  font-weight: 500;
}

/* Better input styling */
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 0;
  border-color: hsl(var(--ring));
}

/* Enhanced card readability */
.card h3,
.card h4,
.card h5,
.card h6 {
  color: hsl(var(--card-foreground));
}

/* Improved text contrast for descriptions */
.subtitle,
.description {
  color: hsl(var(--muted-foreground));
  font-size: 1.1rem;
}

/* Loading animation */
.animate-spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Fade in animation */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.animate-fade-in {
  animation: fadeIn 0.6s ease-out;
}

/* Slide transition animations */
@keyframes slideInFromRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInFromLeft {
  from {
    opacity: 0;
    transform: translateX(-100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOutToLeft {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(-100%);
  }
}

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

.animate-slide-in-right {
  animation: slideInFromRight 0.5s ease-out;
}

.animate-slide-in-left {
  animation: slideInFromLeft 0.5s ease-out;
}

.animate-slide-out-left {
  animation: slideOutToLeft 0.5s ease-in;
}

.animate-slide-out-right {
  animation: slideOutToRight 0.5s ease-in;
}

/* Pulse animation for loading */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Bounce animation */
@keyframes bounce {
  0%, 20%, 53%, 80%, 100% {
    transform: translate3d(0, 0, 0);
  }
  40%, 43% {
    transform: translate3d(0, -8px, 0);
  }
  70% {
    transform: translate3d(0, -4px, 0);
  }
  90% {
    transform: translate3d(0, -2px, 0);
  }
}

.animate-bounce {
  animation: bounce 1s infinite;
}

/* Progress bar animation */
@keyframes progress {
  from {
    width: 0%;
  }
  to {
    width: 100%;
  }
}

.animate-progress {
  animation: progress 4s linear;
}