@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  html, body {
    height: 100%;
    overflow: hidden;
  }
  
  * {
    box-sizing: border-box;
  }
  
  /* Disable text selection and highlighting for drawing interface */
  .drawing-interface {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Custom scrollbar */
  .custom-scrollbar::-webkit-scrollbar {
    width: 8px;
  }
  
  .custom-scrollbar::-webkit-scrollbar-track {
    @apply bg-gray-100 dark:bg-gray-800 rounded-full;
  }
  
  .custom-scrollbar::-webkit-scrollbar-thumb {
    @apply bg-gray-300 dark:bg-gray-600 rounded-full;
    transition: background-color 0.2s ease;
  }
  
  .custom-scrollbar::-webkit-scrollbar-thumb:hover {
    @apply bg-gray-400 dark:bg-gray-500;
  }
  
  /* Firefox scrollbar */
  .custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: theme('colors.gray.300') theme('colors.gray.100');
  }
  
  /* Canvas cursor styles */
  .canvas-cursor-pen {
    cursor: crosshair;
  }
  
  .canvas-cursor-brush {
    cursor: crosshair;
  }
  
  .canvas-cursor-eraser {
    cursor: crosshair;
  }
  
  .canvas-cursor-highlighter {
    cursor: crosshair;
  }
  
  /* Animation for drawing strokes */
  @keyframes drawStroke {
    from {
      stroke-dasharray: 1000;
      stroke-dashoffset: 1000;
    }
    to {
      stroke-dashoffset: 0;
    }
  }
  
  .animate-draw-stroke {
    animation: drawStroke 2s ease-in-out;
  }
  
  /* Loading spinner */
  @keyframes spin {
    to {
      transform: rotate(360deg);
    }
  }
  
  .animate-spin-slow {
    animation: spin 3s linear infinite;
  }
  
  /* Pulse animation for pending operations */
  @keyframes pulse-color {
    0%, 100% {
      background-color: theme('colors.blue.500');
    }
    50% {
      background-color: theme('colors.blue.300');
    }
  }
  
  .animate-pulse-color {
    animation: pulse-color 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  }
  
  /* Glass morphism effect */
  .glass-effect {
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.18);
  }
  
  /* Dark glass effect */
  .glass-effect-dark {
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.18);
  }
  
  /* Touch device optimizations */
  @media (hover: none) and (pointer: coarse) {
    .hover-only {
      display: none;
    }
    
    .touch-target {
      min-height: 44px;
      min-width: 44px;
    }
    
    /* Larger touch targets for tools */
    .tool-button {
      min-height: 48px;
      min-width: 48px;
    }
  }
  
  /* High DPI display optimizations */
  @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    canvas {
      image-rendering: -webkit-optimize-contrast;
      image-rendering: crisp-edges;
    }
  }
  
  /* Stylus/Apple Pencil optimizations */
  @media (hover: none) and (pointer: fine) {
    .stylus-precision {
      cursor: crosshair;
    }
  }
  
  /* Focus styles for accessibility */
  .focus-ring {
    @apply focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2;
  }
  
  /* Canvas specific styles */
  .canvas-container {
    position: relative;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
  }
  
  .canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 10;
  }
  
  /* Tool panel animations */
  .tool-panel-enter {
    transform: translateX(-100%);
  }
  
  .tool-panel-enter-active {
    transform: translateX(0);
    transition: transform 0.3s ease-out;
  }
  
  .tool-panel-exit {
    transform: translateX(0);
  }
  
  .tool-panel-exit-active {
    transform: translateX(-100%);
    transition: transform 0.3s ease-in;
  }
  
  /* Custom range slider styles */
  input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: theme('colors.gray.200');
    outline: none;
  }
  
  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: theme('colors.primary.500');
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }
  
  input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: theme('colors.primary.500');
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }
  
  /* Color picker styles */
  input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
  }
  
  input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
  }
  
  input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 6px;
  }
  
  /* Notification styles */
  .notification-enter {
    opacity: 0;
    transform: translateY(-20px);
  }
  
  .notification-enter-active {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s, transform 0.3s;
  }
  
  .notification-exit {
    opacity: 1;
    transform: translateY(0);
  }
  
  .notification-exit-active {
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.3s, transform 0.3s;
  }
  
  /* Loading states */
  .skeleton {
    @apply animate-pulse bg-gray-200 rounded;
  }
  
  .skeleton-text {
    @apply h-4 bg-gray-200 rounded animate-pulse;
  }
  
  .skeleton-circle {
    @apply rounded-full bg-gray-200 animate-pulse;
  }
  
  /* Error states */
  .error-shake {
    animation: shake 0.5s ease-in-out;
  }
  
  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
  }
  
  /* Success states */
  .success-bounce {
    animation: bounce 0.5s ease-in-out;
  }
  
  @keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
  }
  
  /* Responsive design helpers */
  @media (max-width: 640px) {
    .mobile-hidden {
      display: none;
    }
    
    .mobile-full {
      width: 100%;
      height: 100%;
    }
  }
  
  @media (min-width: 1024px) {
    .desktop-grid {
      display: grid;
      grid-template-columns: auto 1fr auto;
      height: 100vh;
    }
  }
  
  /* Print styles */
  @media print {
    .no-print {
      display: none !important;
    }
    
    .canvas-container {
      page-break-inside: avoid;
    }
  }
}

@layer components {
  /* Component-specific styles will be added here */
  .btn-icon {
    @apply w-10 h-10 flex items-center justify-center rounded-lg transition-colors;
  }
  
  .btn-icon:hover {
    @apply bg-gray-100;
  }
  
  .btn-icon.active {
    @apply bg-primary-100 text-primary-700;
  }
  
  .panel-shadow {
    box-shadow: 
      0 10px 15px -3px rgba(0, 0, 0, 0.1),
      0 4px 6px -2px rgba(0, 0, 0, 0.05);
  }
  
  .canvas-shadow {
    box-shadow: 
      0 20px 25px -5px rgba(0, 0, 0, 0.1),
      0 10px 10px -5px rgba(0, 0, 0, 0.04),
      inset 0 0 0 1px rgba(0, 0, 0, 0.05);
  }
}

@layer utilities {
  /* Utility classes for specific needs */
  .text-shadow {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  }
  
  .text-shadow-lg {
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  
  .backdrop-blur-xs {
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
  
  .transform-gpu {
    transform: translateZ(0);
  }
  
  .perspective-1000 {
    perspective: 1000px;
  }
  
  .backface-hidden {
    backface-visibility: hidden;
  }
  
  .will-change-transform {
    will-change: transform;
  }
  
  .hardware-acceleration {
    transform: translateZ(0);
    backface-visibility: hidden;
    will-change: transform;
  }
}