/* Enhanced Accessibility and Mobile Improvements for With You */
/* Supplements main.css with advanced accessibility and performance features */

/* Enhanced CSS Custom Properties for Accessibility */
:root {
    /* Accessibility-specific variables */
    --focus-color: #2c5f5f;
    --focus-outline-width: 3px;
    --focus-outline-offset: 2px;
    
    /* iOS Safari specific variables */
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
    --safe-area-inset-left: env(safe-area-inset-left);
    --safe-area-inset-right: env(safe-area-inset-right);
    
    /* Touch target sizes for accessibility */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    --touch-target-stress: 56px;
    
    /* Animation variables */
    --animation-speed: 0.3s;
    --animation-easing: cubic-bezier(0.4, 0, 0.2, 1);
    --animation-speed-fast: 0.15s;
    --animation-speed-slow: 0.5s;
}

/* iOS Safari viewport fixes */
@supports (-webkit-touch-callout: none) {
    html {
        /* iOS Safari viewport height fix */
        height: -webkit-fill-available;
    }
    
    body {
        min-height: -webkit-fill-available;
        
        /* Prevent zoom on input focus */
        -webkit-text-size-adjust: 100%;
        -webkit-font-smoothing: antialiased;
        
        /* Safe area support */
        padding-top: var(--safe-area-inset-top);
        padding-bottom: var(--safe-area-inset-bottom);
        padding-left: var(--safe-area-inset-left);
        padding-right: var(--safe-area-inset-right);
    }
    
    /* Fix for iOS Safari address bar hiding */
    .full-height {
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    /* Prevent iOS bounce scroll */
    .prevent-bounce {
        overscroll-behavior: none;
        -webkit-overflow-scrolling: touch;
    }
    
    /* iOS Safari input zoom prevention */
    input, textarea, select {
        font-size: 16px !important; /* Prevents zoom */
        transform: scale(1); /* Alternative zoom prevention */
    }
    
    /* iOS Safari button improvements */
    button, .btn {
        -webkit-appearance: none;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

/* Enhanced focus management */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--color-primary, #2c5f5f);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 9999;
    transition: top var(--animation-speed, 0.3s) ease;
    font-weight: 500;
}

.skip-link:focus {
    top: calc(6px + var(--safe-area-inset-top, 0px));
    outline: var(--focus-outline-width) solid var(--focus-color);
    outline-offset: var(--focus-outline-offset);
}

/* Enhanced focus indicators for keyboard navigation */
.focus-visible {
    outline: var(--focus-outline-width) solid var(--focus-color) !important;
    outline-offset: var(--focus-outline-offset) !important;
    border-radius: 4px;
}

/* Stress mode enhancements */
.stress-mode {
    --touch-target-min: var(--touch-target-stress);
    --font-size-base: 18px;
    --spacing-base: 24px;
}

.stress-mode .action-card {
    min-height: var(--touch-target-stress);
    font-size: 18px;
    margin-bottom: 24px;
    padding: 24px;
    border: 3px solid transparent;
    transition: all var(--animation-speed) ease;
}

.stress-mode .action-card:focus,
.stress-mode .action-card:hover {
    border-color: var(--color-accent, #d4af37);
    transform: scale(1.02);
}

.stress-mode .cta-primary,
.stress-mode .cta-secondary {
    min-height: var(--touch-target-stress);
    font-size: 18px;
    padding: 20px 32px;
    font-weight: 600;
}

.stress-mode .record-button {
    min-height: 80px;
    min-width: 80px;
    font-size: 20px;
}

.stress-mode .nav-links a {
    min-height: var(--touch-target-stress);
    font-size: 18px;
    padding: 20px 24px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --focus-outline-width: 4px;
        --focus-outline-offset: 3px;
    }
    
    .action-card,
    .cta-primary,
    .cta-secondary {
        border: 2px solid currentColor;
    }
    
    .focus-visible {
        outline-width: 4px;
        outline-offset: 3px;
        outline-color: currentColor;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        transition-delay: 0ms !important;
    }
    
    .wave-bar.animated {
        animation: none;
    }
    
    .smooth-transform {
        transition: none;
    }
    
    /* Keep essential feedback animations but make them instant */
    .haptic-light,
    .haptic-medium,
    .haptic-strong {
        animation-duration: 0.01ms;
    }
}

/* Enhanced touch targets for all interactive elements */
button, .btn, a, input, textarea, select {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    position: relative;
}

/* Improve touch response */
button, .btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    user-select: none;
    
    /* Add visual feedback for touch */
    transition: all var(--animation-speed) ease;
}

button:active, .btn:active {
    transform: scale(0.98);
}

button:disabled, .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Enhanced input accessibility */
input, textarea, select {
    padding: 12px 16px;
    border: 2px solid var(--color-text-light, #ccc);
    border-radius: 8px;
    font-family: inherit;
    font-size: 16px; /* Prevent iOS zoom */
    transition: border-color var(--animation-speed) ease;
    background-color: white;
    
    /* iOS improvements */
    -webkit-appearance: none;
    appearance: none;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--color-primary, #2c5f5f);
    outline: none;
    box-shadow: 0 0 0 3px rgba(44, 95, 95, 0.1);
}

/* Error states */
.error-message {
    color: var(--color-error, #e74c3c);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: none;
    font-weight: 500;
}

.error-message.show {
    display: block;
    animation: slideInDown var(--animation-speed) ease;
}

input.error, textarea.error {
    border-color: var(--color-error, #e74c3c);
    background-color: rgba(231, 76, 60, 0.05);
}

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

/* Enhanced toast notifications */
.toast {
    position: fixed;
    top: calc(20px + var(--safe-area-inset-top, 0px));
    right: calc(20px + var(--safe-area-inset-right, 0px));
    background: white;
    color: var(--color-text, #333);
    padding: 16px 20px;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    z-index: 10000;
    opacity: 0;
    transform: translateX(100%);
    transition: all var(--animation-speed) ease;
    max-width: calc(100vw - 40px - var(--safe-area-inset-left, 0px) - var(--safe-area-inset-right, 0px));
    word-wrap: break-word;
    border-left: 4px solid var(--color-primary, #2c5f5f);
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.success {
    background: var(--color-success, #27ae60);
    color: white;
    border-left-color: rgba(255, 255, 255, 0.3);
}

.toast.error {
    background: var(--color-error, #e74c3c);
    color: white;
    border-left-color: rgba(255, 255, 255, 0.3);
}

.toast.warning {
    background: var(--color-warning, #f39c12);
    color: white;
    border-left-color: rgba(255, 255, 255, 0.3);
}

.toast.info {
    background: var(--color-primary, #2c5f5f);
    color: white;
    border-left-color: rgba(255, 255, 255, 0.3);
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toast-icon {
    font-size: 1.125rem;
}

.toast-message {
    flex: 1;
    font-weight: 500;
}

/* Enhanced modal accessibility */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    
    /* Safe area support */
    padding-top: calc(20px + var(--safe-area-inset-top, 0px));
    padding-bottom: calc(20px + var(--safe-area-inset-bottom, 0px));
    padding-left: calc(20px + var(--safe-area-inset-left, 0px));
    padding-right: calc(20px + var(--safe-area-inset-right, 0px));
    
    /* Prevent iOS bounce scroll */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

.modal.show {
    display: flex;
    animation: fadeIn var(--animation-speed) ease;
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: min(90vw, 600px);
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    
    /* iOS Safari scroll fix */
    -webkit-overflow-scrolling: touch;
    
    /* Animation */
    animation: modalSlideIn var(--animation-speed) ease;
}

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

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 24px 16px 24px;
    border-bottom: 1px solid var(--color-text-light, #e5e7eb);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-primary, #2c5f5f);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-text-muted, #7f8c8d);
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all var(--animation-speed) ease;
}

.modal-close:hover,
.modal-close:focus {
    background: rgba(0, 0, 0, 0.1);
    color: var(--color-text, #333);
}

/* Connection status indicator */
#connection-indicator {
    position: fixed;
    top: calc(20px + var(--safe-area-inset-top, 0px));
    right: calc(20px + var(--safe-area-inset-right, 0px));
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    z-index: 10000;
    transition: all var(--animation-speed) ease;
    opacity: 0;
    transform: translateY(-10px);
    backdrop-filter: blur(10px);
}

/* Performance optimizations */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* Loading skeleton animation */
.loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
    border-radius: 4px;
}

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

/* Voice recording enhancements */
.voice-modal {
    backdrop-filter: blur(8px);
    background: rgba(0, 0, 0, 0.7);
}

.voice-recorder {
    text-align: center;
    padding: 2rem;
}

.recorder-visual {
    margin-bottom: 2rem;
}

.sound-wave {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    height: 60px;
}

.wave-bar {
    width: 4px;
    height: 20px;
    background: var(--color-primary, #2c5f5f);
    border-radius: 2px;
    transition: all var(--animation-speed) ease;
}

.wave-bar.animated {
    animation: wave-pulse 1.5s ease-in-out infinite;
}

.wave-bar:nth-child(1) { animation-delay: 0s; }
.wave-bar:nth-child(2) { animation-delay: 0.1s; }
.wave-bar:nth-child(3) { animation-delay: 0.2s; }
.wave-bar:nth-child(4) { animation-delay: 0.3s; }
.wave-bar:nth-child(5) { animation-delay: 0.4s; }

@keyframes wave-pulse {
    0%, 100% {
        height: 20px;
        opacity: 0.5;
    }
    50% {
        height: 60px;
        opacity: 1;
    }
}

.record-button {
    background: var(--color-primary, #2c5f5f);
    color: white;
    border: none;
    border-radius: 50%;
    width: 80px;
    height: 80px;
    font-size: 24px;
    cursor: pointer;
    transition: all var(--animation-speed) ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    box-shadow: 0 4px 12px rgba(44, 95, 95, 0.3);
}

.record-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(44, 95, 95, 0.4);
}

.record-button:active {
    transform: scale(0.98);
}

.record-button.recording {
    background: var(--color-error, #e74c3c);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
    }
    50% {
        box-shadow: 0 4px 20px rgba(231, 76, 60, 0.6), 0 0 0 10px rgba(231, 76, 60, 0.1);
    }
}

/* Haptic feedback simulation */
.haptic-light { animation: haptic-light 0.1s ease-out; }
.haptic-medium { animation: haptic-medium 0.15s ease-out; }
.haptic-strong { animation: haptic-strong 0.2s ease-out; }

@keyframes haptic-light {
    0% { transform: scale(1); }
    50% { transform: scale(0.98); }
    100% { transform: scale(1); }
}

@keyframes haptic-medium {
    0% { transform: scale(1); }
    25% { transform: scale(0.96); }
    75% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

@keyframes haptic-strong {
    0% { transform: scale(1); }
    20% { transform: scale(0.94); }
    40% { transform: scale(1.04); }
    60% { transform: scale(0.98); }
    80% { transform: scale(1.01); }
    100% { transform: scale(1); }
}

/* Print styles */
@media print {
    .no-print,
    .nav,
    .modal,
    .toast,
    #connection-indicator,
    .skip-link,
    .voice-modal {
        display: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
        line-height: 1.4;
    }
    
    .action-card,
    .cta-primary,
    .cta-secondary {
        border: 1px solid #000 !important;
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }
    
    /* Print URLs after links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* Dark mode support (for future implementation) */
@media (prefers-color-scheme: dark) {
    .auto-dark-mode {
        --color-text: #e5e7eb;
        --color-text-light: #9ca3af;
        --color-text-muted: #6b7280;
        --color-secondary: #1f2937;
        --color-white: #111827;
        --focus-color: #60a5fa;
    }
}

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

.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

.visually-hidden {
    position: absolute !important;
    clip: rect(1px, 1px, 1px, 1px) !important;
    padding: 0 !important;
    border: 0 !important;
    height: 1px !important;
    width: 1px !important;
    overflow: hidden;
}

/* Enhanced responsive breakpoint utilities */
@media (max-width: 320px) {
    .stress-mode {
        --touch-target-min: 48px;
        --spacing-base: 16px;
    }
    
    .toast {
        font-size: 14px;
        padding: 12px 16px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .modal {
        padding: 10px;
    }
}

@media (max-width: 480px) {
    .modal-content {
        max-width: 95vw;
        margin: 0;
    }
    
    .modal-header {
        padding: 16px;
    }
}