/**
 * UX Quick Wins - P0 Improvements
 * Implements accessibility, touch targets, and visual enhancements
 */

/* ============================================
   1. SKIP NAVIGATION LINK (WCAG 2.4.1)
   ============================================ */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary, #2563eb);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 10000;
  border-radius: 0 0 4px 0;
  font-weight: 600;
  transition: top 0.2s ease;
}

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

/* Screen reader only text */
.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;
}

/* ============================================
   2. TOUCH TARGET SIZES (WCAG 2.5.5)
   ============================================ */

/* Ensure all interactive elements meet 44x44px minimum */
.sidebar-toggle,
.logout-btn,
.mobile-menu-btn,
button,
.btn,
a.nav-item,
input[type="submit"],
input[type="button"],
input[type="reset"] {
  min-width: 44px !important;
  min-height: 44px !important;
}

/* Small buttons need padding adjustment */
.btn-sm,
.copy-btn,
.add-item-btn,
.tool-btn {
  padding: 12px 16px !important;
  min-height: 44px !important;
}

/* Icon-only buttons */
.icon-btn,
.close-btn,
.modal-close,
.remove-item {
  min-width: 44px !important;
  min-height: 44px !important;
  padding: 10px !important;
}

/* ============================================
   3. FOCUS INDICATORS (WCAG 2.4.7)
   ============================================ */

/* Enhanced focus visible for all interactive elements */
*:focus-visible {
  outline: 3px solid var(--primary, #2563eb);
  outline-offset: 2px;
}

/* Specific elements */
.btn:focus-visible,
.nav-item:focus-visible,
.action-card:focus-visible {
  outline: 3px solid var(--primary, #2563eb);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.15);
}

/* Links */
a:focus-visible {
  outline: 3px solid var(--primary, #2563eb);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Form inputs */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid var(--primary, #2563eb);
  outline-offset: 2px;
  border-color: var(--primary, #2563eb);
}

/* ============================================
   4. REQUIRED FIELD INDICATORS
   ============================================ */

.required-indicator {
  color: var(--error, #ef4444);
  font-weight: bold;
  margin-left: 0.25rem;
}

.form-required-legend {
  display: block;
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  color: var(--gray-600, #4b5563);
}

.form-required-legend::before {
  content: '* ';
  color: var(--error, #ef4444);
  font-weight: bold;
}

/* ============================================
   5. TOAST NOTIFICATION SYSTEM
   ============================================ */

.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  background: white;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  padding: 1rem 1.5rem;
  min-width: 300px;
  max-width: 400px;
  pointer-events: all;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  animation: slideIn 0.3s ease-out;
  border-left: 4px solid;
}

.toast-success {
  border-left-color: var(--success, #10b981);
}

.toast-error {
  border-left-color: var(--error, #ef4444);
}

.toast-warning {
  border-left-color: var(--warning, #f59e0b);
}

.toast-info {
  border-left-color: var(--primary, #2563eb);
}

.toast-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  line-height: 1;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--gray-900, #111827);
}

.toast-message {
  font-size: 0.875rem;
  color: var(--gray-600, #4b5563);
  line-height: 1.4;
}

.toast-close {
  background: none;
  border: none;
  color: var(--gray-400, #9ca3af);
  cursor: pointer;
  padding: 0.25rem;
  flex-shrink: 0;
  font-size: 1.25rem;
  line-height: 1;
  min-width: 24px;
  min-height: 24px;
}

.toast-close:hover {
  color: var(--gray-600, #4b5563);
}

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

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(120%);
    opacity: 0;
  }
}

.toast.closing {
  animation: slideOut 0.3s ease-in forwards;
}

/* ============================================
   6. FORM VALIDATION STATES
   ============================================ */

.field-error {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: #fef2f2;
  border-left: 3px solid var(--error, #ef4444);
  border-radius: 4px;
  font-size: 0.875rem;
  color: #dc2626;
}

.field-error::before {
  content: '⚠';
  font-weight: bold;
}

.field-success {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: #f0fdf4;
  border-left: 3px solid var(--success, #10b981);
  border-radius: 4px;
  font-size: 0.875rem;
  color: #059669;
}

.field-success::before {
  content: '✓';
  font-weight: bold;
}

input.error,
textarea.error,
select.error {
  border-color: var(--error, #ef4444) !important;
  background: #fef2f2;
}

input.error:focus,
textarea.error:focus,
select.error:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

input.valid,
textarea.valid,
select.valid {
  border-color: var(--success, #10b981);
}

/* Character counter for textareas */
.field-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}

.char-count {
  font-size: 0.75rem;
  color: var(--gray-500, #6b7280);
}

.char-count.warning {
  color: var(--warning, #f59e0b);
  font-weight: 600;
}

/* ============================================
   7. IMPROVED CONTRAST (WCAG 1.4.3)
   ============================================ */

.help-text {
  color: #52525b !important; /* Darker gray for better contrast */
}

/* ============================================
   8. MOBILE OPTIMIZATIONS
   ============================================ */

@media (max-width: 640px) {
  .toast {
    min-width: calc(100vw - 2rem);
    max-width: calc(100vw - 2rem);
  }

  .toast-container {
    right: 1rem;
    left: 1rem;
  }

  /* Ensure touch targets on mobile */
  button,
  .btn,
  a.nav-item,
  input[type="submit"],
  input[type="button"] {
    min-height: 48px !important;
    padding: 12px 16px !important;
  }

  /* Mobile text sizes */
  input,
  textarea,
  select {
    font-size: 16px !important; /* Prevent zoom on iOS */
  }

  label {
    font-size: 1rem !important;
  }
}

/* ============================================
   9. ARIA LIVE REGION FOR ANNOUNCEMENTS
   ============================================ */

#announcer {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   10. LOADING STATES
   ============================================ */

.skeleton-loader {
  position: relative;
  overflow: hidden;
}

.skeleton-box {
  display: block;
  width: 60px;
  height: 32px;
  background: linear-gradient(
    90deg,
    #e5e7eb 25%,
    #f3f4f6 50%,
    #e5e7eb 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 4px;
}

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

[data-loading="false"] .skeleton-box {
  display: none;
}

/* ============================================
   11. UTILITY CLASSES
   ============================================ */

.hidden {
  display: none !important;
}

.invisible {
  visibility: hidden !important;
}

.pointer-events-none {
  pointer-events: none !important;
}

.cursor-pointer {
  cursor: pointer !important;
}

.cursor-not-allowed {
  cursor: not-allowed !important;
}
