/**
 * KKG Portal - Main Stylesheet
 * Includes: Dark Mode, Accessibility, Animations
 */

/* ============================================
   CSS Custom Properties (CSS Variables)
   ============================================ */

:root {
  /* Light Theme (Default) */
  --color-bg-primary: #ffffff;
  --color-bg-secondary: #f8fafc;
  --color-bg-tertiary: #f1f5f9;
  --color-bg-elevated: #ffffff;
  --color-bg-overlay: rgba(0, 0, 0, 0.5);
  
  --color-text-primary: #1e293b;
  --color-text-secondary: #475569;
  --color-text-tertiary: #64748b;
  --color-text-muted: #94a3b8;
  --color-text-inverse: #ffffff;
  
  --color-border-default: #e2e8f0;
  --color-border-strong: #cbd5e1;
  
  --color-accent-primary: #3b82f6;
  --color-accent-secondary: #8b5cf6;
  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  
  --transition-fast: 150ms ease;
  --transition-normal: 300ms ease;
  --transition-slow: 500ms ease;
  
  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  
  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;
  
  /* Font Sizes */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
}

/* ============================================
   Dark Theme
   ============================================ */

[data-theme="dark"],
.dark {
  --color-bg-primary: #0f172a;
  --color-bg-secondary: #1e293b;
  --color-bg-tertiary: #334155;
  --color-bg-elevated: #1e293b;
  --color-bg-overlay: rgba(0, 0, 0, 0.7);
  
  --color-text-primary: #f8fafc;
  --color-text-secondary: #e2e8f0;
  --color-text-tertiary: #94a3b8;
  --color-text-muted: #64748b;
  --color-text-inverse: #0f172a;
  
  --color-border-default: #334155;
  --color-border-strong: #475569;
  
  --color-accent-primary: #60a5fa;
  --color-accent-secondary: #a78bfa;
  --color-success: #4ade80;
  --color-warning: #fbbf24;
  --color-error: #f87171;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.4), 0 8px 10px -6px rgb(0 0 0 / 0.3);
}

/* Auto dark mode based on system preference */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg-primary: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-bg-tertiary: #334155;
    --color-bg-elevated: #1e293b;
    --color-bg-overlay: rgba(0, 0, 0, 0.7);
    
    --color-text-primary: #f8fafc;
    --color-text-secondary: #e2e8f0;
    --color-text-tertiary: #94a3b8;
    --color-text-muted: #64748b;
    --color-text-inverse: #0f172a;
    
    --color-border-default: #334155;
    --color-border-strong: #475569;
    
    --color-accent-primary: #60a5fa;
    --color-accent-secondary: #a78bfa;
  }
}

/* ============================================
   Base Styles
   ============================================ */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--color-bg-secondary);
  color: var(--color-text-primary);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* ============================================
   Dark Mode Toggle Button
   ============================================ */

.theme-toggle {
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-full);
  padding: var(--spacing-sm) var(--spacing-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  color: var(--color-text-primary);
  transition: all var(--transition-fast);
}

.theme-toggle:hover {
  background: var(--color-bg-elevated);
  transform: scale(1.05);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--color-accent-primary);
  outline-offset: 2px;
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  width: 1.25rem;
  height: 1.25rem;
}

/* Hide appropriate icon based on theme */
[data-theme="dark"] .theme-toggle .icon-sun,
.dark .theme-toggle .icon-sun {
  display: none;
}

[data-theme="light"] .theme-toggle .icon-moon,
:root:not([data-theme="dark"]):not(.dark) .theme-toggle .icon-moon {
  display: none;
}

/* ============================================
   Accessibility Enhancements
   ============================================ */

/* Focus visible styles */
:focus-visible {
  outline: 2px solid var(--color-accent-primary);
  outline-offset: 2px;
}

/* Skip to content link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-accent-primary);
  color: white;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  text-decoration: none;
  font-weight: 600;
  z-index: 9999;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: var(--spacing-md);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --color-border-default: #000000;
    --color-border-strong: #000000;
  }
  
  [data-theme="dark"],
  .dark {
    --color-border-default: #ffffff;
    --color-border-strong: #ffffff;
  }
}

/* Screen reader only class */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   Component Overrides for Dark Mode
   ============================================ */

/* Cards */
.dark .bg-white,
[data-theme="dark"] .bg-white {
  background-color: var(--color-bg-elevated) !important;
}

/* Text colors */
.dark .text-gray-800,
.dark .text-gray-900,
[data-theme="dark"] .text-gray-800,
[data-theme="dark"] .text-gray-900 {
  color: var(--color-text-primary) !important;
}

.dark .text-gray-600,
.dark .text-gray-700,
[data-theme="dark"] .text-gray-600,
[data-theme="dark"] .text-gray-700 {
  color: var(--color-text-secondary) !important;
}

.dark .text-gray-500,
[data-theme="dark"] .text-gray-500 {
  color: var(--color-text-tertiary) !important;
}

/* Borders */
.dark .border-gray-100,
.dark .border-gray-200,
[data-theme="dark"] .border-gray-100,
[data-theme="dark"] .border-gray-200 {
  border-color: var(--color-border-default) !important;
}

/* Backgrounds */
.dark .bg-gray-50,
.dark .bg-gray-100,
[data-theme="dark"] .bg-gray-50,
[data-theme="dark"] .bg-gray-100 {
  background-color: var(--color-bg-tertiary) !important;
}

/* Input fields */
.dark input,
.dark textarea,
.dark select,
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
  background-color: var(--color-bg-primary);
  color: var(--color-text-primary);
  border-color: var(--color-border-default);
}

.dark input::placeholder,
.dark textarea::placeholder,
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: var(--color-text-muted);
}

/* Hover states in dark mode */
.dark .hover\:bg-gray-50:hover,
[data-theme="dark"] .hover\:bg-gray-50:hover {
  background-color: var(--color-bg-tertiary) !important;
}

/* ============================================
   Animations
   ============================================ */

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

.animate-fade-in {
  animation: fadeIn var(--transition-normal) ease-out;
}

/* Slide up animation */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-slide-up {
  animation: slideUp var(--transition-slow) ease-out;
}

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

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

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

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

/* Bounce animation */
@keyframes bounce {
  0%, 100% {
    transform: translateY(-5%);
    animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  }
  50% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  }
}

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

/* ============================================
   Loading States
   ============================================ */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-bg-tertiary) 25%,
    var(--color-bg-secondary) 50%,
    var(--color-bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  body {
    background: white !important;
    color: black !important;
  }
  
  nav,
  footer,
  .no-print,
  .theme-toggle {
    display: none !important;
  }
  
  .bg-gradient-to-r,
  .bg-gradient-to-br {
    background: #f0f0f0 !important;
    color: black !important;
  }
}

/* ============================================
   Scrollbar Styling
   ============================================ */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--color-bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* Firefox scrollbar */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) var(--color-bg-secondary);
}

/* ============================================
   Selection Styling
   ============================================ */

::selection {
  background-color: var(--color-accent-primary);
  color: white;
}

/* ============================================
   Responsive Images
   ============================================ */

img {
  max-width: 100%;
  height: auto;
}

/* ============================================
   Form Enhancements
   ============================================ */

input:disabled,
textarea:disabled,
select:disabled,
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Checkbox and Radio accessibility */
input[type="checkbox"],
input[type="radio"] {
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
}

/* ============================================
   Toast Notifications
   ============================================ */

.toast-container {
  position: fixed;
  bottom: var(--spacing-lg);
  right: var(--spacing-lg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.toast {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  padding: var(--spacing-md);
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease-out;
  max-width: 350px;
}

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

.toast-success {
  border-left: 4px solid var(--color-success);
}

.toast-error {
  border-left: 4px solid var(--color-error);
}

.toast-warning {
  border-left: 4px solid var(--color-warning);
}

.toast-info {
  border-left: 4px solid var(--color-accent-primary);
}