/* Utility classes */

/* PWA and Offline Utilities */
@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Offline state styling */
body.offline {
    filter: grayscale(20%);
}

body.offline .online-only {
    opacity: 0.5;
    pointer-events: none;
}

.offline-badge {
    background: #dc3545;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    margin-left: 8px;
}

.online-badge {
    background: #28a745;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    margin-left: 8px;
}

/* Loading states */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

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

/* Display utilities */
.hidden {
    display: none !important;
}

.block {
    display: block !important;
}

.inline-block {
    display: inline-block !important;
}

.flex {
    display: flex !important;
}

/* Text utilities */
.text-center {
    text-align: center !important;
}

.text-left {
    text-align: left !important;
}

.text-right {
    text-align: right !important;
}

/* Margin utilities */
.m-0 { margin: 0 !important; }
.m-1 { margin: 0.25rem !important; }
.m-2 { margin: 0.5rem !important; }
.m-3 { margin: 1rem !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 0.25rem !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-3 { margin-top: 1rem !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }

/* Padding utilities */
.p-0 { padding: 0 !important; }
.p-1 { padding: 0.25rem !important; }
.p-2 { padding: 0.5rem !important; }
.p-3 { padding: 1rem !important; }

/* Color utilities - Using CSS variables */
.text-muted {
    color: var(--text-muted) !important; /* was: #718096 */
}

.text-primary {
    color: var(--text-brand) !important; /* was: #4e80fe */
}

.text-danger {
    color: var(--text-danger) !important; /* was: #c53030 */
}

.text-success {
    color: var(--text-success) !important; /* was: #2f855a */
}

/* Background utilities - Using CSS variables */
.bg-light {
    background-color: var(--bg-light) !important; /* was: #f7fafc */
}

.bg-dark {
    background-color: var(--bg-dark) !important; /* was: #2d3748 */
}

.bg-primary {
    background-color: var(--btn-primary-bg) !important; /* was: #4e80fe */
}

/* Responsive utilities */
@media (max-width: 768px) {
    .container {
        margin: 10px;
        padding: 15px;
    }
    
    .chat-message-container {
        padding: 10px;
    }
    
    .chat-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .chat-header-left {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .chat-header-right {
        width: 100%;
        justify-content: flex-start;
    }
    
    .chat-title {
        font-size: 20px;
    }
    
    .message {
        padding: 15px;
    }
    
    .message-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .chat-meta {
        flex-direction: column;
        gap: 5px;
    }
    
    .chat-meta-item {
        margin-right: 0;
    }
}

.streaming-answer pre.assistant-output {
  white-space: pre-wrap;
  font-family: var(--mono-font, "Hack", monospace);
  margin: 0;
}

.modal-content.small {
  max-width: 480px;
}

/* Enhanced Offline UI Styles */
.offline-mode {
  filter: grayscale(20%);
}

.offline-mode .online-only {
  opacity: 0.5;
  pointer-events: none;
}

.offline-badge {
  background: #dc3545;
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  margin-left: 8px;
}

.online-badge {
  background: #28a745;
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  margin-left: 8px;
}

/* Sync Status Indicators */
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
}

.sync-status.syncing {
  background: #fff3cd;
  color: #856404;
}

.sync-status.synced {
  background: #d1ecf1;
  color: #0c5460;
}

.sync-status.error {
  background: #f8d7da;
  color: #721c24;
}

.sync-status.offline {
  background: #e2e3e5;
  color: #383d41;
}

/* Queued Actions Display */
.queued-actions-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 1000;
  max-width: 300px;
  max-height: 400px;
  overflow-y: auto;
}

.queued-actions-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.queued-actions-list {
  padding: 8px 0;
}

.queued-action-item {
  padding: 8px 16px;
  border-bottom: 1px solid #f7fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.queued-action-item:last-child {
  border-bottom: none;
}

.queued-action-type {
  font-size: 12px;
  color: #4a5568;
}

.queued-action-time {
  font-size: 11px;
  color: #718096;
}

/* Enhanced Loading States for Offline Mode */
.offline-loading {
  background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: 4px;
  color: transparent;
}

.offline-placeholder {
  background: #f7fafc;
  border: 1px dashed #cbd5e0;
  border-radius: 6px;
  padding: 20px;
  text-align: center;
  color: #718096;
}

.offline-placeholder i {
  font-size: 24px;
  margin-bottom: 8px;
  display: block;
}

/* Enhanced Conflict Resolution Styles */
.conflict-retry-btn {
  background: #ffc107;
  color: #212529;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.conflict-error {
  font-size: 11px;
  color: #dc3545;
  display: block;
  margin-top: 2px;
}

.conflict-retries {
  font-size: 11px;
  color: #856404;
  display: block;
  margin-top: 2px;
}

/* Conflict Resolution Status */
.conflict-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
}

.conflict-status.resolved {
  background: #d1ecf1;
  color: #0c5460;
}

.conflict-status.retrying {
  background: #fff3cd;
  color: #856404;
}

.conflict-status.ignored {
  background: #e2e3e5;
  color: #383d41;
}

/* App Shell Skeleton Screens */
.skeleton-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: white;
  z-index: 9999;
  display: flex;
  flex-direction: column;
}

.skeleton-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid #e2e8f0;
}

.skeleton-logo {
  width: 120px;
  height: 32px;
}

.skeleton-nav {
  width: 200px;
  height: 32px;
}

.skeleton-content {
  display: flex;
  flex: 1;
  padding: 2rem;
  gap: 2rem;
}

.skeleton-sidebar {
  width: 250px;
  height: 100%;
}

.skeleton-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.skeleton-item {
  height: 60px;
  border-radius: 8px;
}

/* Enhanced Skeleton Animation */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

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

/* Progressive Enhancement - No-JS fallbacks */
.no-js-warning {
  background: #fff3cd;
  border: 1px solid #ffeaa7;
  color: #856404;
  padding: 1rem;
  margin: 1rem;
  border-radius: 8px;
  text-align: center;
}

.no-js-warning.hidden {
  display: none;
}

/* App Shell Transitions */
.app-shell-transition {
  transition: opacity 0.3s ease-in-out;
}

.app-shell-fade-out {
  opacity: 0;
}

/* Form Enhancement Styles */
.field-error {
  border-color: #dc3545 !important;
  background-color: #f8d7da !important;
}

.field-error-message {
  color: #dc3545;
  font-size: 12px;
  margin-top: 4px;
}

/* Button Loading States */
.button-loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 8px;
}

.button-loading-text {
  opacity: 0.8;
}

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

/* API Loading Indicator */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Smooth Transitions */
.smooth-transitions * {
  transition: all 0.2s ease-in-out;
}

/* Enhanced Focus States */
.smooth-transitions button:focus,
.smooth-transitions input:focus,
.smooth-transitions textarea:focus,
.smooth-transitions select:focus {
  outline: 2px solid #4e80fe;
  outline-offset: 2px;
}

/* Improved Accessibility */
.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;
}

/* Progressive Enhancement Styles */
.pwa-enhanced .pwa-feature {
  display: block;
}

.offline-enhanced .offline-feature {
  display: block;
}

.low-memory {
  /* Reduce animations and heavy operations */
  animation-duration: 0.1s !important;
  transition-duration: 0.1s !important;
}

.low-memory .heavy-animation {
  animation: none !important;
}

.slow-connection {
  /* Optimize for slow connections */
}

.slow-connection .background-image {
  background-image: none !important;
}

.slow-connection video {
  display: none;
}

.reduced-motion * {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

.high-contrast {
  /* High contrast color scheme */
  --text-primary: #000000;
  --text-secondary: #333333;
  --background-primary: #ffffff;
  --background-secondary: #f0f0f0;
  --border-color: #000000;
}

.touch-device .hover-effect {
  /* Reduce hover effects on touch devices */
  pointer-events: none;
}

.touch-device button,
.touch-device a {
  /* Larger touch targets */
  min-height: 44px;
  min-width: 44px;
}

/* PWA Install Button */
.pwa-install-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #4e80fe;
  color: white;
  border: none;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1000;
  transition: all 0.3s ease;
}

.pwa-install-btn:hover {
  background: #3b6fe0;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

/* PWA Install Prompt */
.pwa-install-prompt {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  border: 1px solid #e1e5e9;
  z-index: 10000;
  animation: slideInUp 0.3s ease-out;
  max-width: 320px;
  overflow: hidden;
}

.pwa-prompt-content {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.pwa-prompt-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.pwa-prompt-text {
  flex: 1;
}

.pwa-prompt-text h3 {
  margin: 0 0 4px 0;
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
}

.pwa-prompt-text p {
  margin: 0;
  font-size: 14px;
  color: #666;
  line-height: 1.4;
}

.pwa-prompt-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.pwa-prompt-install,
.pwa-prompt-dismiss {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.pwa-prompt-install {
  background: #2563eb;
  color: white;
}

.pwa-prompt-install:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

.pwa-prompt-dismiss {
  background: #f3f4f6;
  color: #374151;
}

.pwa-prompt-dismiss:hover {
  background: #e5e7eb;
}

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

/* Feature Detection Indicators */
.feature-indicator {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  margin-left: 6px;
}

.feature-indicator.supported {
  background: #d1ecf1;
  color: #0c5460;
}

.feature-indicator.unsupported {
  background: #f8d7da;
  color: #721c24;
}

/* Lazy Loading States */
[data-lazy] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

[data-lazy].loaded {
  opacity: 1;
}

/* Enhanced Focus for Keyboard Navigation */
.keyboard-navigation button:focus,
.keyboard-navigation a:focus,
.keyboard-navigation input:focus,
.keyboard-navigation textarea:focus,
.keyboard-navigation select:focus {
  outline: 3px solid #4e80fe;
  outline-offset: 2px;
}

/* Screen Reader Enhancements */
.sr-announce {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.live-region {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Responsive Offline UI */
@media (max-width: 768px) {
  .queued-actions-panel {
    bottom: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }

  .sync-status {
    font-size: 10px;
    padding: 3px 6px;
  }

  .conflict-actions {
    flex-direction: column;
    gap: 4px;
  }

  .conflict-resolve-btn,
  .conflict-retry-btn,
  .conflict-ignore-btn {
    width: 100%;
    font-size: 11px;
    padding: 4px 8px;
  }

  /* Mobile Skeleton Screens */
  .skeleton-content {
    flex-direction: column;
    padding: 1rem;
  }

  .skeleton-sidebar {
    width: 100%;
    height: 200px;
  }

  .skeleton-header {
    padding: 1rem;
  }
}