/* Enhanced Focus Indicators */
*:focus-visible {
  outline: 3px solid var(--accent-blue);
  outline-offset: 2px;
  border-radius: 4px;
}

button:focus-visible,
.btn:focus-visible {
  outline: 3px solid var(--accent-blue);
  outline-offset: 3px;
}

/* Loading Spinner */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Loading Skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-secondary) 25%,
    var(--surface-muted) 50%,
    var(--bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

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

.skeleton-text {
  height: 16px;
  margin-bottom: 8px;
}

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

.skeleton-card {
  height: 120px;
  margin-bottom: 12px;
}

/* Enhanced Empty States */
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state h3 {
  margin: 0 0 var(--space-2);
  color: var(--text-primary);
  font-size: 1.25rem;
}

.empty-state p {
  margin: 0;
  font-size: 0.95rem;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* Improved Feedback Toast */
.feedback {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + var(--space-4));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  display: none;
  align-items: center;
  gap: var(--space-3);
  z-index: 1200;
  max-width: min(520px, calc(100% - 24px));
  box-shadow: var(--shadow-soft);
  min-width: 300px;
  pointer-events: none;
}

.feedback.active {
  display: flex;
  animation: slideIn 0.3s ease;
}

.feedback.success {
  border-color: var(--accent-green);
  background: linear-gradient(135deg,
    rgba(34, 197, 94, 0.1),
    var(--bg-card)
  );
}

.feedback.success::before {
  content: '✓';
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--accent-green);
  color: white;
  border-radius: 50%;
  font-weight: bold;
  flex-shrink: 0;
}

.feedback.error {
  border-color: var(--accent-red);
  background: linear-gradient(135deg,
    rgba(239, 68, 68, 0.1),
    var(--bg-card)
  );
}

.feedback.error::before {
  content: '✕';
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--accent-red);
  color: white;
  border-radius: 50%;
  font-weight: bold;
  flex-shrink: 0;
}

.feedback.warning {
  border-color: var(--accent-amber);
  background: linear-gradient(135deg,
    rgba(245, 158, 11, 0.1),
    var(--bg-card)
  );
}

.feedback.warning::before {
  content: '⚠';
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--accent-amber);
  color: #000;
  border-radius: 50%;
  font-weight: bold;
  flex-shrink: 0;
}

/* Print Styles for QR Codes */
@media print {
  body {
    background: white;
  }

  .bg-gradient,
  header,
  .controls,
  .student-list,
  .nav-links,
  .theme-toggle,
  .btn,
  button,
  .feedback {
    display: none !important;
  }

  .qr-preview {
    display: block !important;
  }

  .preview-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 20px !important;
    page-break-inside: avoid;
  }

  .qr-card {
    page-break-inside: avoid;
    border: 2px solid #000 !important;
    padding: 15px !important;
    background: white !important;
  }

  .qr-card canvas {
    margin: 0 auto;
    display: block;
  }

  .qr-card .name,
  .qr-card .id {
    color: #000 !important;
    text-align: center;
  }
}

/* Skip Link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent-blue);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  border-radius: 0 0 4px 0;
  z-index: 1000;
  font-weight: 600;
}

.skip-link:focus {
  top: 0;
}

/* Improved Modal Accessibility */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  z-index: 100;
}

.modal-overlay.active {
  display: flex;
}

.modal[role="dialog"] {
  position: relative;
}

/* Keyboard Navigation Hints */
.location-btn:focus::after {
  content: '';
  position: absolute;
  inset: -4px;
  border: 3px solid var(--accent-blue);
  border-radius: var(--radius-md);
  pointer-events: none;
}

/* Hover and Active States */
.location-btn {
  position: relative;
  transition: all 0.18s ease;
}

.location-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.location-btn:active:not(:disabled) {
  transform: translateY(0);
}

/* Better Button States */
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn:not(:disabled):hover {
  filter: brightness(1.1);
}

.btn:not(:disabled):active {
  transform: translateY(1px);
}

/* ARIA Live Regions */
[aria-live] {
  position: relative;
}

/* Status Badge Improvements */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: capitalize;
}

.status-normal {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
}

.status-overtime {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
}

.status-timeout {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
}

.status-active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
}

/* Tooltips */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  white-space: nowrap;
  margin-bottom: 8px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  z-index: 1000;
  pointer-events: none;
}

[data-tooltip]:hover::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--border-color);
  margin-bottom: 2px;
  z-index: 1000;
}

/* Smooth Transitions */
* {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

button, .btn, a {
  transition: all 0.18s ease;
}
