/**
 * Unified Styles for Doksa.io Analysis Modules
 *
 * This stylesheet ensures consistent styling across all analysis modules
 * including Literature Review and Qualitative Analysis.
 */

/* ========================================================================
   ROOT VARIABLES & DESIGN TOKENS
   ======================================================================== */

:root {
  /* Primary Colors */
  --primary-gradient: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  --primary-purple: #8b5cf6;
  --primary-indigo: #6366f1;

  /* Status Colors */
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;

  /* Neutral Colors */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;

  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Z-index Scale */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  --z-notification: 1080;
}

/* Dark Mode Variables */
[data-theme="dark"] {
  --gray-50: #1f2937;
  --gray-100: #374151;
  --gray-200: #4b5563;
  --gray-300: #6b7280;
  --gray-400: #9ca3af;
  --gray-500: #d1d5db;
  --gray-600: #e5e7eb;
  --gray-700: #f3f4f6;
  --gray-800: #f9fafb;
  --gray-900: #ffffff;
}

/* ========================================================================
   CONTAINER LAYOUTS
   ======================================================================== */

.container-main {
  max-width: 80rem; /* 1280px - standardized to max-w-7xl */
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--spacing-md);
  padding-right: var(--spacing-md);
}

.container-content {
  max-width: 72rem; /* 1152px */
}

.container-narrow {
  max-width: 64rem; /* 1024px */
}

/* ========================================================================
   FORM ELEMENTS & VALIDATION
   ======================================================================== */

/* Base Form Control Styles */
.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--gray-900);
  background-color: white;
  background-clip: padding-box;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-lg);
  transition: all var(--transition-normal);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.form-control:focus {
  outline: 2px solid transparent;
  outline-offset: 2px;
  border-color: var(--primary-purple);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

/* Enhanced Contrast for Better Readability */
.form-control:not(:placeholder-shown) {
  background-color: #fefefe;
  color: var(--gray-900);
}

/* Dark Mode Form Controls */
.dark .form-control {
  background-color: var(--gray-700);
  border-color: var(--gray-600);
  color: var(--gray-100);
}

.dark .form-control:focus {
  border-color: var(--primary-indigo);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Global Input/Textarea/Select Readability - Catch all edge cases */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
textarea,
select {
  color: #111827 !important; /* gray-900 - dark text for light backgrounds */
}

/* Only apply white text to inputs that are actually on dark backgrounds */
.dark input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not(.bg-white):not([class*="bg-white"]),
.dark textarea:not(.bg-white):not([class*="bg-white"]),
.dark select:not(.bg-white):not([class*="bg-white"]) {
  color: #ffffff !important;
}

/* Ensure placeholder text is visible but distinct */
/* WCAG AA: 4.5:1 contrast ratio minimum */
input::placeholder,
textarea::placeholder {
  color: #6b7280; /* gray-500 - better contrast than gray-400 */
  opacity: 1;
}

.dark input::placeholder,
.dark textarea::placeholder {
  color: #9ca3af; /* gray-400 - lighter for dark mode, better contrast */
  opacity: 1;
}

/* Validation States */
.field-valid {
  border-color: var(--success) !important;
}

.field-valid:focus {
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1) !important;
}

.field-error {
  border-color: var(--error) !important;
}

.field-error:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}

/* Validation Icons */
.validation-icon {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

/* Error Messages */
.error-message {
  display: flex;
  align-items: center;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--error);
}

.error-message i {
  margin-right: 0.25rem;
}

/* ========================================================================
   BUTTONS & INTERACTIVE ELEMENTS
   ======================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  border-radius: var(--radius-lg);
  transition: all var(--transition-normal);
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  min-height: 48px; /* Mobile touch target */
}

.btn-primary {
  background: var(--primary-gradient);
  color: white;
  border: none;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

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

.btn-secondary:hover {
  background-color: var(--gray-50);
  border-color: var(--gray-400);
}

/* ========================================================================
   CARDS & CONTAINERS
   ======================================================================== */

.card {
  background-color: white;
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  padding: var(--spacing-xl);
  transition: all var(--transition-normal);
}

.card:hover {
  box-shadow: var(--shadow-2xl);
}

.dark .card {
  background-color: var(--gray-800);
  border: 1px solid var(--gray-700);
}

/* ========================================================================
   LOADING & PROGRESS INDICATORS
   ======================================================================== */

.loading-spinner {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid var(--gray-300);
  border-radius: 50%;
  border-top-color: var(--primary-purple);
  animation: spin 1s linear infinite;
}

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

.progress-bar {
  height: 0.75rem;
  background-color: var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary-gradient);
  border-radius: var(--radius-lg);
  transition: width var(--transition-slow);
  position: relative;
  overflow: hidden;
}

.progress-bar-fill::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  animation: shimmer 3.5s infinite ease-in-out;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ========================================================================
   TOOLTIPS & POPOVERS
   ======================================================================== */

.tooltip {
  position: relative;
  display: inline-block;
}

.tooltip-content {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.5rem 0.75rem;
  background-color: var(--gray-900);
  color: white;
  font-size: 0.875rem;
  border-radius: var(--radius-md);
  white-space: nowrap;
  z-index: var(--z-tooltip);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  pointer-events: none;
}

.tooltip:hover .tooltip-content {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(-0.5rem);
}

/* ========================================================================
   ACCESSIBILITY HELPERS
   ======================================================================== */

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

.focus-visible {
  outline: 2px solid var(--primary-purple);
  outline-offset: 2px;
}

/* Skip to main content link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary-gradient);
  color: white;
  padding: 0.5rem 1rem;
  z-index: var(--z-fixed);
  text-decoration: none;
  border-radius: var(--radius-md);
}

.skip-link:focus {
  top: 0.5rem;
  left: 0.5rem;
}

/* ========================================================================
   MOBILE OPTIMIZATIONS
   ======================================================================== */

/* Ensure minimum touch target sizes on mobile */
@media (max-width: 768px) {
  /* Increase touch targets */
  button,
  input,
  textarea,
  select,
  a.btn,
  .clickable {
    min-height: 48px;
    min-width: 48px;
  }

  /* Larger font sizes for better readability */
  input,
  textarea,
  select {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.875rem 1rem;
  }

  /* Adjust spacing for mobile */
  .container-main {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .card {
    padding: 1.5rem;
    border-radius: var(--radius-xl);
  }

  /* Stack form elements on mobile */
  .form-row {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  /* Larger buttons on mobile */
  .btn {
    padding: 1rem 1.5rem;
    font-size: 1.125rem;
  }

  /* Adjust modal sizing */
  .modal-content {
    margin: 1rem;
    max-height: calc(100vh - 2rem);
  }

  /* Better table scrolling */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Tablet optimizations */
@media (min-width: 768px) and (max-width: 1024px) {
  .container-main {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

/* ========================================================================
   ANIMATIONS & TRANSITIONS
   ======================================================================== */

/* Fade transitions */
.fade-enter-active,
.fade-leave-active {
  transition: opacity var(--transition-normal);
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* Slide transitions */
.slide-enter-active,
.slide-leave-active {
  transition: transform var(--transition-normal), opacity var(--transition-normal);
}

.slide-enter-from {
  transform: translateY(-1rem);
  opacity: 0;
}

.slide-leave-to {
  transform: translateY(1rem);
  opacity: 0;
}

/* Scale transitions */
.scale-enter-active,
.scale-leave-active {
  transition: transform var(--transition-normal), opacity var(--transition-normal);
}

.scale-enter-from,
.scale-leave-to {
  transform: scale(0.95);
  opacity: 0;
}

/* Modal fade */
.modal-fade-enter-active,
.modal-fade-leave-active {
  transition: all var(--transition-normal);
}

.modal-fade-enter-from,
.modal-fade-leave-to {
  opacity: 0;
  transform: scale(0.95);
}

/* ========================================================================
   UTILITIES
   ======================================================================== */

/* Text utilities */
.text-gradient {
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Overflow utilities */
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Spacing utilities */
.space-y-1 > * + * { margin-top: 0.25rem; }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-3 > * + * { margin-top: 0.75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }
.space-y-8 > * + * { margin-top: 2rem; }

/* Focus trap for modals */
.focus-trap {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-backdrop);
}

/* ========================================================================
   PRINT STYLES
   ======================================================================== */

@media print {
  .no-print,
  .btn,
  .modal,
  .tooltip {
    display: none !important;
  }

  body {
    font-size: 12pt;
    color: black;
    background: white;
  }

  .container-main {
    max-width: 100%;
    padding: 0;
  }

  .card {
    box-shadow: none;
    border: 1px solid #000;
    page-break-inside: avoid;
  }
}

/* ========================================================================
   DOKSA SPINNER - Branded Loading Animation

   Usage:
   1. Use the SVG markup with class "doksa-spinner"
   2. Add size modifier: doksa-spinner-sm (40px) or doksa-spinner-lg (120px)
   3. For inline/button use: doksa-spinner-inline (1em)
   ======================================================================== */

.doksa-spinner {
    width: 80px;
    height: 80px;
}

.doksa-spinner-sm {
    width: 48px;
    height: 48px;
}

.doksa-spinner-lg {
    width: 120px;
    height: 120px;
}

.doksa-spinner-inline {
    width: 1.5em;
    height: 1.5em;
    min-width: 24px;
    min-height: 24px;
    vertical-align: middle;
}

.doksa-spinner .dot {
    fill: #B8860B;
    opacity: 0.2;
    animation: doksa-pulse-out 2s ease-out infinite;
}

.doksa-spinner .d-letter {
    fill: #B8860B;
}

/* Animation rings - inner fires first, outer fires last */
.doksa-spinner .inner { animation-delay: 0s; }
.doksa-spinner .middle { animation-delay: 0.3s; }
.doksa-spinner .outer { animation-delay: 0.6s; }

@keyframes doksa-pulse-out {
    0%, 100% {
        opacity: 0.2;
        transform: scale(0.8);
    }
    30%, 45% {
        opacity: 1;
        transform: scale(1.3);
        filter: drop-shadow(0 0 6px rgba(184, 134, 11, 1));
    }
    70% {
        opacity: 0.3;
        transform: scale(1);
    }
}

/* Layout utilities for spinner + text combinations */

/* Stacked layout: spinner centered above text */
.doksa-loading-stacked {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    text-align: center;
    padding: 2rem 1rem;
}

.doksa-loading-stacked .doksa-loading-text {
    color: #92400E;
    font-size: 0.9375rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    animation: doksa-text-pulse 2s ease-in-out infinite;
}

/* Dark mode support */
.dark .doksa-loading-stacked .doksa-loading-text,
[data-theme="dark"] .doksa-loading-stacked .doksa-loading-text {
    color: #FCD34D;
}

/* Inline layout: spinner before text on same line */
.doksa-loading-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.doksa-loading-inline .doksa-loading-text {
    opacity: 0.9;
}

/* Subtle text pulse animation for loading states */
@keyframes doksa-text-pulse {
    0%, 100% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
}