/* Custom styles for Lead Generator */

/* ========================================
   SKIP NAVIGATION (ACCESSIBILITY)
   ======================================== */
.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  padding: 12px 24px;
  background: #B92322;
  color: white;
  font-weight: 600;
  border-radius: 0 0 12px 12px;
  text-decoration: none;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
  outline: 2px solid white;
  outline-offset: 2px;
}

/* ========================================
   SMOOTH TRANSITIONS
   ======================================== */
* {
  transition-property: background-color, border-color, color, fill, stroke, opacity, transform, box-shadow;
  transition-timing-function: ease-in-out;
  transition-duration: 150ms;
}

/* ========================================
   DARK MODE CONTRAST FIXES
   ======================================== */
.dark input,
.dark select,
.dark textarea {
  background-color: #374151 !important;
  border-color: #4b5563 !important;
  color: #f9fafb !important;
}

.dark input::placeholder,
.dark textarea::placeholder {
  color: #9ca3af !important;
  opacity: 1;
}

.dark .card,
.dark .bg-white {
  background-color: var(--card-bg) !important;
}

.dark table tbody tr:hover {
  background-color: rgba(185, 35, 34, 0.1) !important;
}

/* Ensure muted text passes WCAG AA contrast in dark mode */
.dark .text-gray-400 {
  color: #9ca3af !important;
}

.dark .text-gray-500 {
  color: #d1d5db !important;
}

/* Dark mode modal backdrop */
.dark .modal-backdrop,
.dark [class*="bg-black/50"] {
  background-color: rgba(0, 0, 0, 0.7) !important;
}

/* Dark mode labels */
.dark label {
  color: #e5e7eb;
}

/* Dark mode help text */
.dark .text-xs.text-gray-500 {
  color: #9ca3af !important;
}

/* Dark mode info boxes */
.dark .bg-blue-50 {
  background-color: rgba(185, 35, 34, 0.12) !important;
  border-color: rgba(185, 35, 34, 0.3) !important;
}
.dark .bg-blue-50 .text-blue-800,
.dark .bg-blue-50 .text-blue-700 {
  color: #fca5a5 !important;
}

/* ========================================
   FOCUS STATES (ACCESSIBILITY)
   ======================================== */
input:focus,
select:focus,
textarea:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(185, 35, 34, 0.3);
  border-color: #B92322 !important;
}

button:focus,
a:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(185, 35, 34, 0.3);
}

/* Focus visible for keyboard users */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #B92322;
  outline-offset: 2px;
}

/* ========================================
   BUTTON IMPROVEMENTS
   ======================================== */
.btn {
  position: relative;
  overflow: hidden;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

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

/* Loading state for buttons */
.btn.loading,
.btn-loading {
  pointer-events: none;
  opacity: 0.7;
  cursor: wait;
}

.btn.loading .btn-text {
  visibility: hidden;
}

.btn-loading {
  display: inline-flex !important;
  align-items: center;
  gap: 0.5rem;
}

.btn.loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
.animate-spin {
  animation: spin 1s linear infinite;
}

/* Secondary button improvements */
.btn-secondary:hover {
  background-color: #f3f4f6;
  border-color: #B92322;
  color: #991b1b;
}

.dark .btn-secondary {
  background-color: #374151;
  border-color: #4b5563;
  color: #e5e7eb;
}

.dark .btn-secondary:hover {
  background-color: #4b5563;
  border-color: #B92322;
  color: #f9fafb;
}

/* ========================================
   TABLE & ROW HOVER EFFECTS
   ======================================== */
tbody tr {
  transition: background-color 0.15s ease, transform 0.15s ease;
}

tbody tr:hover {
  background-color: rgba(185, 35, 34, 0.05);
}

/* Sortable header styling */
th[data-sort] {
  cursor: pointer;
  user-select: none;
}

th[data-sort]:hover {
  background-color: rgba(185, 35, 34, 0.1);
}

th[data-sort]:hover .sort-icon {
  color: #B92322;
}

/* ========================================
   CARD HOVER EFFECTS
   ======================================== */
.card-interactive {
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.card-interactive:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border-color: #fca5a5;
}

/* ========================================
   MOBILE RESPONSIVE TABLES
   ======================================== */

/* Horizontal scroll wrapper with fade indicator */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.table-responsive::-webkit-scrollbar {
  height: 4px;
}

/* Scroll hint for horizontally scrollable tables */
@media (max-width: 768px) {
  .table-responsive {
    margin-left: -1rem;
    margin-right: -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .table-responsive::after {
    content: '';
    position: sticky;
    right: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(to left, var(--card-bg, white), transparent);
    pointer-events: none;
  }
}

@media (max-width: 768px) {
  /* Make table rows stack on mobile */
  .mobile-cards tbody tr {
    display: block;
    margin-bottom: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 1rem;
    background: white;
  }

  .mobile-cards thead {
    display: none;
  }

  .mobile-cards tbody td {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border: none;
  }

  .mobile-cards tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    margin-right: 1rem;
  }

  /* Checkbox column on mobile */
  .mobile-cards tbody td:first-child {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
  }

  .dark .mobile-cards tbody tr {
    background: var(--card-bg);
    border-color: var(--border-color);
  }

  /* Hide low-priority columns on mobile */
  .hide-on-mobile {
    display: none !important;
  }
}

/* Larger touch targets on mobile */
@media (max-width: 768px) {
  input[type="checkbox"] {
    width: 20px;
    height: 20px;
  }

  button, .btn {
    min-height: 44px;
    padding: 12px 16px;
  }

  input, select, textarea {
    min-height: 44px;
    font-size: 16px; /* Prevent zoom on iOS */
  }
}

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

.dark .skeleton {
  background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
  background-size: 200% 100%;
}

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

.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
}

.skeleton-text-sm {
  height: 0.75rem;
  width: 60%;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

/* ========================================
   SCROLLBAR STYLING
   ======================================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}

.dark ::-webkit-scrollbar-track {
  background: #1f2937;
}

.dark ::-webkit-scrollbar-thumb {
  background: #4b5563;
}

.dark ::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* ========================================
   TOOLTIP STYLING
   ======================================== */
[title] {
  position: relative;
}

/* ========================================
   ALERT IMPROVEMENTS
   ======================================== */
.alert {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: 0.75rem;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.alert-success {
  background-color: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.alert-error {
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.alert-warning {
  background-color: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

.dark .alert-success {
  background-color: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
}

.dark .alert-error {
  background-color: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.dark .alert-warning {
  background-color: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.3);
  color: #fcd34d;
}

.alert-info {
  background-color: #eef2ff;
  border: 1px solid #c7d2fe;
  color: #3730a3;
}

.dark .alert-info {
  background-color: rgba(185, 35, 34, 0.1);
  border-color: rgba(185, 35, 34, 0.3);
  color: #fca5a5;
}

/* Alert close button */
.alert-close {
  opacity: 0.6;
}
.alert-close:hover {
  opacity: 1;
}

/* Flash message container spacing */
.flash-container {
  margin-bottom: 1rem;
}

/* ========================================
   PROGRESS BAR IMPROVEMENTS
   ======================================== */
.progress-bar {
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background-color: #e5e7eb;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
  background: linear-gradient(90deg, #B92322, #7A7A7A);
}

.dark .progress-bar {
  background-color: #374151;
}

/* ========================================
   BADGE/TAG IMPROVEMENTS
   ======================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  transition: transform 0.15s ease;
}

.badge:hover {
  transform: scale(1.05);
}

/* ========================================
   LOADING 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;
}

/* Status dot animation */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.active {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ========================================
   COPY BUTTON FEEDBACK
   ======================================== */
.copy-btn {
  transition: color 0.15s ease, transform 0.15s ease;
}

.copy-btn:hover {
  transform: scale(1.1);
}

.copy-btn:active {
  transform: scale(0.95);
}

/* ========================================
   MODAL IMPROVEMENTS
   ======================================== */
.modal-backdrop {
  animation: fadeIn 0.2s ease;
}

.modal-content {
  animation: slideUp 0.3s ease;
}

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

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

/* ========================================
   EMPTY STATES
   ======================================== */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: #6b7280;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  color: #d1d5db;
}

.dark .empty-state {
  color: #9ca3af;
}

.dark .empty-state-icon {
  color: #4b5563;
}

/* ========================================
   SELECTION HIGHLIGHT
   ======================================== */
tr.selected {
  background-color: rgba(185, 35, 34, 0.1) !important;
}

.dark tr.selected {
  background-color: rgba(185, 35, 34, 0.2) !important;
}

/* ========================================
   LINK IMPROVEMENTS
   ======================================== */
a:not(.btn):not(.nav-link) {
  transition: color 0.15s ease;
}

a:not(.btn):not(.nav-link):hover {
  text-decoration: underline;
}

/* External link indicator */
a[target="_blank"]::after {
  content: " ↗";
  font-size: 0.75em;
  opacity: 0.7;
}

/* ========================================
   INPUT GROUP STYLING
   ======================================== */
.input-group {
  display: flex;
  gap: 0.5rem;
}

.input-group input {
  flex: 1;
}

.input-group button {
  flex-shrink: 0;
}

/* ========================================
   FLOATING LABEL (optional future use)
   ======================================== */
.floating-label {
  position: relative;
}

.floating-label input:placeholder-shown + label {
  transform: translateY(0);
  font-size: 1rem;
  color: #9ca3af;
}

.floating-label input:focus + label,
.floating-label input:not(:placeholder-shown) + label {
  transform: translateY(-1.5rem);
  font-size: 0.75rem;
  color: #B92322;
}

/* ========================================
   TAB NAVIGATION
   ======================================== */
.settings-tab {
  transition: all 0.15s ease;
}

.settings-tab:hover:not(.active) {
  background-color: rgba(185, 35, 34, 0.05);
}

.dark .settings-tab {
  color: #9ca3af;
}

.dark .settings-tab:hover:not(.active) {
  color: #e5e7eb;
  background-color: rgba(185, 35, 34, 0.1);
  border-color: #4b5563;
}

.dark .settings-tab.active {
  color: #fca5a5;
  border-color: #B92322;
}

.dark .border-gray-200 {
  border-color: #374151;
}

/* Tab panel transitions */
.tab-panel {
  animation: fadeIn 0.2s ease;
}

.tab-panel.hidden {
  display: none;
}

/* ========================================
   STICKY TABLE HEADERS
   ======================================== */
.overflow-x-auto {
  -webkit-overflow-scrolling: touch;
}

.sortable-table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: #f9fafb;
}

.dark .sortable-table thead th {
  background-color: var(--bg-tertiary);
}

/* ========================================
   MOBILE MODAL FIXES
   ======================================== */
@media (max-width: 640px) {
  /* Ensure modals are usable on small screens */
  [aria-modal="true"] > div > div:not(.fixed) {
    max-height: 90vh;
    margin: 1rem;
  }

  /* Pagination wrapping */
  .flex.items-center.justify-center.gap-2,
  .flex.items-center.justify-center.gap-1 {
    flex-wrap: wrap;
  }

  /* Larger pagination touch targets on mobile */
  .flex.items-center.justify-center.gap-1 a,
  .flex.items-center.justify-center.gap-1 span {
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ========================================
   TABLE OVERFLOW SCROLL INDICATOR
   ======================================== */
.overflow-x-auto {
  position: relative;
}

/* Subtle gradient indicating scrollable content */
.table-scroll-wrapper {
  position: relative;
}

.table-scroll-wrapper::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 24px;
  background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.table-scroll-wrapper.has-scroll::after {
  opacity: 1;
}

.dark .table-scroll-wrapper::after {
  background: linear-gradient(to left, rgba(31, 41, 55, 0.9), transparent);
}

/* ========================================
   DARK MODE NOTIFICATION DROPDOWN
   ======================================== */
.dark #notification-dropdown {
  background-color: var(--card-bg) !important;
  border-color: var(--border-color) !important;
}

.dark #notification-dropdown .bg-red-50 {
  background-color: rgba(185, 35, 34, 0.15) !important;
}

/* ========================================
   TRUNCATED TEXT WITH ELLIPSIS
   ======================================== */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   REDUCED MOTION
   ======================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
  .no-print,
  nav,
  .btn,
  button {
    display: none !important;
  }

  body {
    background: white !important;
    color: black !important;
  }

  .card {
    box-shadow: none !important;
    border: 1px solid #e5e7eb !important;
  }
}
