/* EILEEN Platform - Main Stylesheet */

/* Base styling */
html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #1f2937;
  line-height: 1.5;
}

/*
 * Button reset — Tailwind preflight is disabled (Bootstrap compatibility)
 * so browser default button styles persist. This removes only the grey
 * background and raised border that browsers add by default. Padding,
 * colour, and font are left alone so Tailwind classes work as expected.
 */
:where(button:not(.btn):not([type="submit"])) {
  background: transparent;
  border: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

/* HTMX Indicators */
.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator {
  opacity: 1;
}

.htmx-request.htmx-indicator {
  opacity: 1;
}

/* Focus styles for accessibility */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* High contrast focus styles when using keyboard navigation */
.js-focus-visible :focus:not(.focus-visible) {
  outline: none;
}

.js-focus-visible .focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
}

/* Toast notifications */
#toast {
  z-index: 50;
}

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

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

.animate-fade-in {
  animation: fadeIn 0.3s ease-in-out;
}

.animate-slide-up {
  animation: slideUp 0.3s ease-in-out;
}

/* Utility classes */
.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;
}

.focus-ring {
  outline: none;
  transition: box-shadow 0.2s;
}

.focus-ring:focus-visible {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #3b82f6;
}

/* Page transitions for HTMX */
.page-transition {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
}

.page-transition.loaded {
  opacity: 1;
  transform: translateY(0);
}

/* Loading indicator */
.loading-spinner {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 0.25rem solid #e5e7eb;
  border-top-color: #3b82f6;
  animation: spinner 0.8s linear infinite;
}

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

/* Back to top button */
.back-to-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: #3b82f6;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  transform: translateY(10px);
  cursor: pointer;
  z-index: 30;
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Global form styles */
.input-focus-ring {
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-focus-ring:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Button styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-weight: 500;
  border-radius: 0.375rem;
  transition: all 0.2s;
  cursor: pointer;
}

.btn-primary {
  background-color: #3b82f6;
  color: white;
  border: none;
}

.btn-primary:hover {
  background-color: #2563eb;
}

.btn-primary:focus {
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
  background-color: white;
  color: #4b5563;
  border: 1px solid #d1d5db;
}

.btn-secondary:hover {
  background-color: #f3f4f6;
}

.btn-secondary:focus {
  box-shadow: 0 0 0 4px rgba(209, 213, 219, 0.5);
}

.btn-danger {
  background-color: #ef4444;
  color: white;
  border: none;
}

.btn-danger:hover {
  background-color: #dc2626;
}

.btn-danger:focus {
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.3);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

.btn-lg {
  padding: 0.625rem 1.25rem;
  font-size: 1rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border-radius: 9999px;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
}

.badge-green {
  background-color: #d1fae5;
  color: #065f46;
}

.badge-yellow {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-red {
  background-color: #fee2e2;
  color: #b91c1c;
}

.badge-blue {
  background-color: #dbeafe;
  color: #1e40af;
}

.badge-gray {
  background-color: #f3f4f6;
  color: #4b5563;
}

/* Card styles */
.card {
  background-color: white;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e5e7eb;
}

.card-body {
  padding: 1.25rem;
}

.card-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid #e5e7eb;
}

/* Alert styles */
.alert {
  padding: 1rem;
  border-radius: 0.375rem;
  margin-bottom: 1rem;
}

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

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

.alert-error {
  background-color: #fee2e2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.alert-info {
  background-color: #dbeafe;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

/* ========================================================================
   iOS Safari Touch Optimization Utility Classes
   ======================================================================== */

/*
 * BACKGROUND: iOS Safari Touch Event Issues
 * ----------------------------------------
 * iOS Safari has specific touch handling behaviors that can make buttons and
 * interactive elements unresponsive or behave inconsistently. This is particularly
 * problematic with HTMX-powered buttons where users may experience:
 * - Buttons not responding to touch/tap
 * - Delayed or missed touch events
 * - Inconsistent behavior between different button implementations
 *
 * SOLUTION: Three-Part iOS Touch Fix
 * ----------------------------------
 * 1. cursor: pointer - Ensures proper cursor behavior
 * 2. -webkit-tap-highlight-color: rgba(0,0,0,0) - Removes iOS blue tap highlight
 * 3. touch-action: manipulation - Optimizes touch handling for interactive elements
 *
 * IMPLEMENTATION HISTORY:
 * - Original fix implemented in PR #241 for iPhone modal button unresponsiveness
 * - Refactored to utility classes in Session 20 (September 6, 2025) for maintainability
 * - Extended across all appointment interface templates for consistency
 *
 * USAGE GUIDELINES:
 * - Use .htmx-button for HTMX-enabled interactive buttons (primary use case)
 * - Use .ios-touch for general interactive elements needing iOS optimization
 * - Use .btn-ios for enhanced button-specific iOS touch handling
 * - Always pair with ontouchstart="" attribute in templates for maximum compatibility
 */

/* General iOS touch optimization for any interactive element */
.ios-touch {
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  touch-action: manipulation;
}

/* Enhanced button-specific iOS touch optimization */
.btn-ios {
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  touch-action: manipulation;
}

/*
 * PRIMARY UTILITY: HTMX-enabled buttons
 * ------------------------------------
 * Use this class for all buttons that use HTMX for dynamic interactions.
 * This ensures consistent, reliable touch behavior on iOS devices.
 *
 * Example usage:
 * <button class="bg-green-600 hover:bg-green-700 text-white htmx-button"
 *         hx-post="/api/endpoint/"
 *         ontouchstart=""
 *         aria-label="Descriptive action">Action</button>
 */
.htmx-button {
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  touch-action: manipulation;
  /* Reset browser default button styling — let Tailwind classes control appearance */
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
}

/* Location Address Input Styling */
.address-autocomplete {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid #e5e7eb;
  border-radius: 0.5rem;
  font-size: 1rem;
  transition: all 0.2s ease-in-out;
  background-color: #fff;
}

.address-autocomplete:focus {
  border-color: #3b82f6;
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.address-autocomplete.focused {
  background-color: #fefefe;
}

.address-autocomplete.is-valid {
  border-color: #22c55e;
  background-color: #f0fdf4;
}

.address-autocomplete.is-invalid {
  border-color: #ef4444;
  background-color: #fef2f2;
}

.address-autocomplete::placeholder {
  color: #9ca3af;
  font-style: italic;
}

/* Google Places Autocomplete Dropdown Styling */
.pac-container {
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.pac-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
}

.pac-item:hover {
  background-color: #f8fafc;
}

.pac-item-selected {
  background-color: #3b82f6;
  color: white;
}

/* Address input with icon */
.address-input-container {
  position: relative;
}

.address-input-container::before {
  content: "📍";
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 1.1rem;
}

.address-input-container .address-autocomplete {
  padding-left: 2.5rem;
}
