/**
 * AUTOMATION STYLES - MEJORADO Y RESPONSIVE
 * Estilos para el sistema de automatización con mejor UX
 * @author Alexis Quiroga- TestConnect
 * @version 2.0
 */

/* ========================================
   VARIABLES CSS
   ======================================== */
:root {
  --primary-blue: #3b82f6;
  --primary-blue-dark: #2563eb;
  --success-green: #10b981;
  --success-green-dark: #059669;
  --error-red: #ef4444;
  --warning-orange: #f59e0b;
  --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;
}

/* ========================================
   MODAL DE AUTOMATIZACIÓN
   ======================================== */

.automation-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.automation-modal.show {
  opacity: 1;
  pointer-events: all;
}

.automation-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
}

.automation-modal-content {
  position: relative;
  background: white;
  width: 90%;
  max-width: 600px;
  margin: 50px auto;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transform: translateY(-20px);
  transition: transform 0.3s ease;
  max-height: 90vh;
  overflow-y: auto;
}

.automation-modal.show .automation-modal-content {
  transform: translateY(0);
}

.automation-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  border-bottom: 1px solid var(--gray-200);
  background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-blue-dark) 100%);
  color: white;
  border-radius: 16px 16px 0 0;
}

.automation-modal-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 12px;
}

.automation-modal-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  font-size: 24px;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.2s;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.automation-modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.automation-modal-body {
  padding: 24px;
}

.automation-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 24px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
}

/* Form Elements */
.form-group-automation {
  margin-bottom: 20px;
}

.label-automation {
  display: block;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-automation,
.select-automation {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.2s;
  background: white;
  font-family: inherit;
}

.input-automation:focus,
.select-automation:focus {
  outline: none;
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.input-automation.valid {
  border-color: var(--success-green);
}

.input-automation.invalid {
  border-color: var(--error-red);
}

.hint-automation {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--gray-500);
}

.form-row-automation {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Sections */
.credentials-section,
.options-section {
  margin-top: 24px;
  padding: 20px;
  background: var(--gray-50);
  border-radius: 12px;
  border: 1px solid var(--gray-200);
}

.section-title-automation {
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 16px;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Toggle Switches */
.toggle-group-automation {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.toggle-item-automation {
  background: white;
  padding: 16px;
  border-radius: 8px;
  border: 2px solid var(--gray-200);
  transition: all 0.2s;
}

.toggle-item-automation:hover {
  border-color: var(--gray-300);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.toggle-label-automation {
  display: flex;
  align-items: center;
  cursor: pointer;
  position: relative;
  padding-left: 60px;
  min-height: 32px;
}

.toggle-label-automation input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider-automation {
  position: absolute;
  left: 0;
  width: 48px;
  height: 28px;
  background: var(--gray-300);
  border-radius: 14px;
  transition: all 0.3s;
}

.toggle-slider-automation::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  top: 4px;
  left: 4px;
  transition: all 0.3s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-label-automation input:checked + .toggle-slider-automation {
  background: var(--primary-blue);
}

.toggle-label-automation input:checked + .toggle-slider-automation::before {
  transform: translateX(20px);
}

.toggle-text-automation {
  font-weight: 500;
  color: var(--gray-700);
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-hint-automation {
  display: block;
  margin-top: 8px;
  margin-left: 60px;
  font-size: 12px;
  color: var(--gray-500);
}

/* Selected Tests Info */
.selected-tests-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: #eff6ff;
  border: 2px solid #bfdbfe;
  border-radius: 8px;
  margin-top: 20px;
  color: #1e40af;
  font-weight: 600;
  font-size: 14px;
}

.selected-tests-info i {
  font-size: 20px;
}

/* Buttons */
.btn-automation {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
}

.btn-cancel-automation {
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn-cancel-automation:hover {
  background: var(--gray-200);
}

.btn-confirm-automation {
  background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-blue-dark) 100%);
  color: white;
}

.btn-confirm-automation:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4);
}

/* ========================================
   RESULTADOS DE AUTOMATIZACIÓN
   ======================================== */

.automation-results-container {
  position: fixed;
  top: 50%;
  right: 20px;
  transform: translateY(-50%) translateX(calc(100% + 20px));
  width: 400px;
  max-height: 85vh;
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  z-index: 9998;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.automation-results-container.show {
  transform: translateY(-50%) translateX(0);
}

.automation-results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-blue-dark) 100%);
  color: white;
  flex-shrink: 0;
}

.automation-results-header h3 {
  margin: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.btn-close-results {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.btn-close-results:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Progress Bar */
.automation-progress-bar {
  position: relative;
  height: 50px;
  background: var(--gray-100);
  margin: 20px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-blue) 0%, var(--primary-blue-dark) 100%);
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  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 2s infinite;
}

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

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-weight: 700;
  font-size: 18px;
  color: var(--gray-800);
  z-index: 1;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

/* Results List */
.automation-results-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px 20px;
  min-height: 0;
}

.automation-results-list::-webkit-scrollbar {
  width: 8px;
}

.automation-results-list::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: 4px;
}

.automation-results-list::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 4px;
}

.automation-results-list::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
}

.automation-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  margin-bottom: 12px;
  background: var(--gray-50);
  border-radius: 10px;
  border-left: 4px solid var(--gray-300);
  transition: all 0.3s;
  animation: slideIn 0.3s ease;
}

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

.automation-result-item.status-pending {
  border-left-color: var(--gray-400);
  background: var(--gray-50);
}

.automation-result-item.status-running {
  border-left-color: var(--primary-blue);
  background: #eff6ff;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.9; }
}

.automation-result-item.status-pass,
.automation-result-item.status-PASSED {
  border-left-color: var(--success-green);
  background: #f0fdf4;
}

.automation-result-item.status-fail,
.automation-result-item.status-FAILED {
  border-left-color: var(--error-red);
  background: #fef2f2;
}

.automation-result-item.status-error,
.automation-result-item.status-ERROR {
  border-left-color: var(--warning-orange);
  background: #fffbeb;
}

.result-item-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.status-pending .result-item-icon {
  color: var(--gray-400);
}

.status-running .result-item-icon {
  color: var(--primary-blue);
}

.status-pass .result-item-icon,
.status-PASSED .result-item-icon {
  color: var(--success-green);
}

.status-fail .result-item-icon,
.status-FAILED .result-item-icon {
  color: var(--error-red);
}

.status-error .result-item-icon,
.status-ERROR .result-item-icon {
  color: var(--warning-orange);
}

.result-item-content {
  flex: 1;
  min-width: 0;
}

.result-item-title {
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 4px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-item-status {
  font-size: 12px;
  color: var(--gray-500);
  font-weight: 500;
}

/* Results Footer */
.automation-results-footer {
  padding: 20px;
  border-top: 2px solid var(--gray-200);
  background: var(--gray-50);
  flex-shrink: 0;
}

.results-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.summary-item {
  text-align: center;
  padding: 12px 8px;
  border-radius: 10px;
  font-weight: 600;
  transition: all 0.2s;
}

.summary-item:hover {
  transform: translateY(-2px);
}

.summary-pass {
  background: #f0fdf4;
  color: var(--success-green);
  border: 2px solid #bbf7d0;
}

.summary-fail {
  background: #fef2f2;
  color: var(--error-red);
  border: 2px solid #fecaca;
}

.summary-error {
  background: #fffbeb;
  color: var(--warning-orange);
  border: 2px solid #fde68a;
}

.summary-item i {
  display: block;
  font-size: 24px;
  margin-bottom: 6px;
}

.summary-item span {
  display: block;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 2px;
}

.btn-download-screenshots {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--success-green) 0%, var(--success-green-dark) 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-family: inherit;
}

.btn-download-screenshots:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4);
}

.btn-download-screenshots:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
  .automation-modal-content {
    width: 95%;
    margin: 20px auto;
    max-height: 95vh;
  }

  .automation-modal-header {
    padding: 20px;
  }

  .automation-modal-header h2 {
    font-size: 20px;
  }

  .automation-modal-body,
  .automation-modal-footer {
    padding: 20px;
  }

  .form-row-automation {
    grid-template-columns: 1fr;
  }

  .automation-results-container {
    width: calc(100% - 40px);
    max-width: 400px;
    right: 20px;
    max-height: 90vh;
  }

  .automation-results-header {
    padding: 16px;
  }

  .automation-results-header h3 {
    font-size: 16px;
  }

  .automation-progress-bar {
    height: 44px;
    margin: 16px;
  }

  .progress-text {
    font-size: 16px;
  }

  .automation-results-list {
    padding: 0 16px 16px 16px;
  }

  .results-summary {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .automation-results-footer {
    padding: 16px;
  }

  .result-item-title {
    white-space: normal;
    line-height: 1.4;
  }
}

@media (max-width: 480px) {
  .automation-modal-content {
    width: 100%;
    margin: 0;
    border-radius: 0;
    max-height: 100vh;
  }

  .automation-modal-header {
    border-radius: 0;
  }

  .automation-results-container {
    width: 100%;
    right: 0;
    border-radius: 0;
    max-height: 100vh;
    top: 0;
    transform: translateY(100%);
  }

  .automation-results-container.show {
    transform: translateY(0);
  }
}

/* ========================================
   DARK MODE (OPCIONAL)
   ======================================== */

@media (prefers-color-scheme: dark) {
  :root {
    --gray-50: #111827;
    --gray-100: #1f2937;
    --gray-200: #374151;
    --gray-300: #4b5563;
    --gray-700: #d1d5db;
    --gray-800: #f3f4f6;
    --gray-900: #f9fafb;
  }

  .automation-modal-content,
  .automation-results-container {
    background: #1f2937;
  }

  .input-automation,
  .select-automation,
  .toggle-item-automation {
    background: #111827;
    color: #f3f4f6;
  }

  .automation-result-item {
    background: #111827;
  }
}

/* ========================================
   VISOR DE SCREENSHOTS
   ======================================== */

.screenshots-viewer {
  margin-top: 20px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #dee2e6;
}

.screenshots-viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #dee2e6;
}

.screenshots-viewer-header h4 {
  margin: 0;
  color: #495057;
  font-size: 1.2rem;
}

.btn-close-viewer {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #6c757d;
  transition: color 0.3s;
}

.btn-close-viewer:hover {
  color: #dc3545;
}

.screenshots-grid {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.screenshot-section h5 {
  margin: 0 0 15px 0;
  color: #343a40;
  font-size: 1.1rem;
  font-weight: 600;
}

.screenshot-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 15px;
}

.screenshot-item {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s, box-shadow 0.2s;
}

.screenshot-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.screenshot-item img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  cursor: pointer;
  display: block;
}

.screenshot-info {
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f9fa;
}

.screenshot-info span {
  font-size: 0.9rem;
  color: #6c757d;
  font-weight: 500;
}

.btn-download-single {
  background: #007bff;
  border: none;
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.3s;
}

.btn-download-single:hover {
  background: #0056b3;
}

.no-screenshots {
  text-align: center;
  padding: 40px;
  color: #6c757d;
  font-size: 1.1rem;
}

/* Modal Fullscreen */
.screenshot-fullscreen-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
}

.fullscreen-overlay {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.fullscreen-content {
  position: relative;
  max-width: 95vw;
  max-height: 95vh;
  cursor: default;
}

.fullscreen-content img {
  max-width: 100%;
  max-height: 95vh;
  display: block;
  border-radius: 4px;
}

.btn-close-fullscreen {
  position: absolute;
  top: -50px;
  right: 0;
  background: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  color: #333;
  transition: background 0.3s, color 0.3s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.btn-close-fullscreen:hover {
  background: #dc3545;
  color: white;
}

/* Botón Ver Screenshots */
.btn-view-screenshots {
  background: #17a2b8;
  border: none;
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.3s, transform 0.2s;
}

.btn-view-screenshots:hover {
  background: #138496;
  transform: translateY(-2px);
}

.footer-actions {
  display: flex;
  gap: 10px;
}

/* Responsive */
@media (max-width: 768px) {
  .screenshot-items {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  
  .screenshot-item img {
    height: 120px;
  }
  
  .footer-actions {
    flex-direction: column;
  }
  
  .footer-actions button {
    width: 100%;
  }
}
