/* Admin Widget Modals */

.pf-admin-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  animation: fadeIn 0.2s ease-out;
  backdrop-filter: blur(2px);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    backdrop-filter: blur(0);
  }
  to {
    opacity: 1;
    backdrop-filter: blur(2px);
  }
}

.pf-admin-modal {
  background: white;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease-out;
}

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

.pf-admin-modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pf-admin-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #111827;
}

.pf-admin-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #6b7280;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.pf-admin-modal-close:hover {
  background: #f3f4f6;
  color: #111827;
}

.pf-admin-modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
  background: white;
}

.pf-admin-modal-footer {
  padding: 16px 24px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.pf-form-group {
  margin-bottom: 20px;
}

.pf-form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: #374151;
  font-size: 14px;
}

.pf-form-group input,
.pf-form-group select,
.pf-form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
}

.pf-form-group input:focus,
.pf-form-group select:focus,
.pf-form-group textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.pf-form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.pf-form-group small {
  display: block;
  margin-top: 4px;
  color: #6b7280;
  font-size: 12px;
}

.pf-form-error {
  color: #dc2626;
  font-size: 12px;
  margin-top: 4px;
}

/* Drag and Drop */
.pf-draggable {
  cursor: move;
  transition: all 0.2s;
}

.pf-draggable:hover {
  transform: translateX(4px);
}

.pf-draggable.dragging {
  opacity: 0.5;
}

.pf-drop-zone {
  position: relative;
}

.pf-drop-zone.drag-over {
  background: #eff6ff;
  border: 2px dashed #3b82f6;
  border-radius: 6px;
}

.pf-drop-zone.drag-over::before {
  content: '↓ Drop here to add as child';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #3b82f6;
  font-weight: 600;
  font-size: 14px;
  pointer-events: none;
}

/* Tree View */
.pf-tree {
  font-family: system-ui, -apple-system, sans-serif;
}

.pf-tree-node {
  margin-left: 24px;
  position: relative;
}

.pf-tree-node:first-child {
  margin-left: 0;
}

.pf-tree-node::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 24px;
  bottom: 0;
  width: 1px;
  background: #e5e7eb;
}

.pf-tree-node::after {
  content: '';
  position: absolute;
  left: -16px;
  top: 24px;
  width: 12px;
  height: 1px;
  background: #e5e7eb;
}

.pf-tree-node-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.pf-tree-node-header:hover {
  background: #f9fafb;
}

.pf-tree-node-header.selected {
  background: #eff6ff;
  border: 1px solid #3b82f6;
}

.pf-tree-toggle {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  color: #6b7280;
  font-size: 12px;
  padding: 0;
  transition: transform 0.2s;
}

.pf-tree-toggle:hover {
  color: #111827;
}

.pf-tree-node.collapsed > .pf-tree-toggle {
  transform: rotate(-90deg);
}

.pf-tree-node.collapsed > .pf-tree-children {
  display: none;
}

.pf-tree-children {
  margin-left: 20px;
}

.pf-tree-icon {
  font-size: 16px;
}

.pf-tree-label {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: #111827;
}

.pf-tree-actions {
  display: none;
  gap: 4px;
}

.pf-tree-node-header:hover .pf-tree-actions {
  display: flex;
}

.pf-tree-action-btn {
  padding: 4px 8px;
  font-size: 12px;
  border: none;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  color: #6b7280;
  transition: all 0.2s;
}

.pf-tree-action-btn:hover {
  background: #3b82f6;
  color: white;
}

/* Loading States */
.pf-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.pf-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* Inline Edit */
.pf-inline-edit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pf-inline-edit input {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid #3b82f6;
  border-radius: 4px;
  font-size: inherit;
  font-family: inherit;
}

.pf-inline-edit-actions {
  display: flex;
  gap: 4px;
}

.pf-inline-edit-btn {
  padding: 4px 8px;
  font-size: 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.pf-inline-edit-save {
  background: #10b981;
  color: white;
}

.pf-inline-edit-save:hover {
  background: #059669;
}

.pf-inline-edit-cancel {
  background: #e5e7eb;
  color: #374151;
}

.pf-inline-edit-cancel:hover {
  background: #d1d5db;
}

/* Select List for Hierarchies */
.pf-select-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  margin-top: 8px;
}

.pf-select-list-item {
  padding: 12px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pf-select-list-item:hover {
  background: #f9fafb;
}

.pf-select-list-item.selected {
  background: #eff6ff;
  border-left: 3px solid #3b82f6;
}

.pf-select-list-item:last-child {
  border-bottom: none;
}

.pf-select-list-empty {
  padding: 40px 20px;
  text-align: center;
  color: #9ca3af;
  font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PHASE 6: POLISH - Animations, Keyboard, Accessibility
   ═══════════════════════════════════════════════════════════════════════════ */

/* Smooth transitions for all interactive elements */
.pf-btn,
.pf-tree-node-header,
.pf-admin-card,
.pf-select-list-item,
.pf-form-group input,
.pf-form-group select,
.pf-form-group textarea {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Micro-interactions on buttons */
.pf-btn:active {
  transform: scale(0.98);
}

.pf-btn:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

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

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

.pf-skeleton-header {
  height: 24px;
  width: 60%;
  margin-bottom: 12px;
}

.pf-skeleton-text {
  height: 16px;
  width: 100%;
  margin-bottom: 8px;
}

.pf-skeleton-text:last-child {
  width: 80%;
}

/* Focus visible for keyboard navigation */
.pf-tree-node-header:focus-visible,
.pf-select-list-item:focus-visible,
.pf-admin-card:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Keyboard navigation helpers */
.pf-tree-node-header,
.pf-select-list-item,
.pf-admin-card {
  cursor: pointer;
  position: relative;
}

.pf-tree-node-header:focus,
.pf-select-list-item:focus,
.pf-admin-card:focus {
  outline: none;
}

/* Improve form focus states */
.pf-form-group input:focus-visible,
.pf-form-group select:focus-visible,
.pf-form-group textarea:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  border-color: #3b82f6;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Success animation */
@keyframes success-pulse {
  0%, 100% { background: transparent; }
  50% { background: #d1fae5; }
}

.pf-success-pulse {
  animation: success-pulse 1s ease-out;
}

/* Error shake animation */
@keyframes error-shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.pf-error-shake {
  animation: error-shake 0.5s ease-out;
}

/* Optimistic update states */
.pf-optimistic-update {
  opacity: 0.6;
  pointer-events: none;
}

/* Progress indicators */
.pf-progress-bar {
  width: 100%;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.pf-progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  border-radius: 2px;
  transition: width 0.3s ease-out;
}

.pf-progress-bar-indeterminate {
  position: absolute;
  width: 30%;
  height: 100%;
  background: linear-gradient(90deg, transparent, #3b82f6, transparent);
  animation: progress-indeterminate 1.5s infinite;
}

@keyframes progress-indeterminate {
  0% { left: -30%; }
  100% { left: 100%; }
}

/* Tooltips for accessibility */
.pf-tooltip {
  position: relative;
}

.pf-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: #1f2937;
  color: white;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
}

.pf-tooltip:hover::after,
.pf-tooltip:focus::after {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

/* ARIA live regions */
.pf-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;
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
  .pf-admin-modal {
    border: 2px solid currentColor;
  }

  .pf-btn {
    border: 2px solid currentColor;
  }

  .pf-tree-node-header.selected {
    border: 3px solid currentColor;
  }
}

/* Dark mode support (future-proofing) */
@media (prefers-color-scheme: dark) {
  .pf-admin-modal {
    background: #1f2937;
    color: #f9fafb;
  }

  .pf-admin-modal-header {
    border-bottom-color: #374151;
  }

  .pf-form-group input,
  .pf-form-group select,
  .pf-form-group textarea {
    background: #111827;
    border-color: #374151;
    color: #f9fafb;
  }

  .pf-admin-modal-footer {
    border-top-color: #374151;
  }
}
