/* Mobile-optimized CSS-only auto-expanding textarea - higher specificity */
textarea.chat-input-optimized {
    /* Basic styling */
    width: 100%;
    border: 1px solid #e5e7eb;
    outline: none;
    background: white;
    resize: none;
    font-family: inherit;
    font-size: 16px; /* Prevents zoom on iOS */
    line-height: 1.5;

    /* Auto-expanding with CSS - no JavaScript needed */
    min-height: 60px; /* Increased for better readability */
    max-height: 160px; /* Higher max for more scrolling */
    height: auto;
    field-sizing: content; /* Modern CSS auto-resize */

    /* Padding for text */
    padding: 16px;

    /* Scrolling only when needed */
    overflow-y: auto;

    /* Performance optimizations for mobile */
    will-change: auto;
    transform: translateZ(0); /* Hardware acceleration */

    /* iOS specific fixes */
    -webkit-appearance: none;
    -webkit-border-radius: 0;
    border-radius: 8px;

    /* Prevent layout shift */
    box-sizing: border-box;
}

/* Role-specific input border colors */
.role-office textarea.chat-input-optimized {
    border: none !important;
}

.role-field textarea.chat-input-optimized {
    border: none !important;
}

/* Fallback for browsers that don't support field-sizing */
@supports not (field-sizing: content) {
    textarea.chat-input-optimized {
        /* Traditional auto-resize approach */
        overflow: hidden;
        resize: none;
        /* Ensure it starts with proper height even for long placeholders */
        height: 60px;
    }

    /* Use a simple script-free approach */
    textarea.chat-input-optimized:focus {
        overflow-y: auto;
        /* Auto-expand on focus for fallback browsers */
        height: auto;
    }
}

/* Mobile specific optimizations */
@media (max-width: 768px) {
    textarea.chat-input-optimized {
        font-size: 16px; /* Prevents zoom on iOS */
        line-height: 1.4;
        min-height: 56px; /* Higher for better mobile UX */
        max-height: 140px; /* More space for scrolling on mobile */
        padding: 14px; /* Slightly smaller padding on mobile */
    }

    /* Mobile button alignment */
    .chat-input-actions {
        height: 56px; /* Match mobile input height */
        align-items: center; /* Force center alignment on mobile */
    }

    /* Fix microphone button alignment on mobile - override MudBlazor .d-block */
    .chat-input-actions .mud-icon-button {
        align-self: center;
        margin: 0;
        display: flex !important; /* Override MudBlazor .d-block !important */
        align-items: center;
        justify-content: center;
        vertical-align: middle;
    }

    /* Override the .d-block specifically for mobile actions */
    .d-block.d-md-none.chat-input-actions {
        display: flex !important;
        align-items: center !important;
    }

    /* Force icon centering on mobile */
    .chat-input-actions .mud-icon-button .mud-icon-root {
        vertical-align: middle;
        line-height: 1;
    }
}

/* Container styling with role colors */
.chat-input-wrapper {
    display: flex;
    align-items: center; /* Changed from flex-end to center for proper vertical alignment */
    gap: 12px;
    padding: 16px;
    background: white;
    border-top: 1px solid #e5e7eb;
    position: sticky;
    bottom: 0;
    z-index: 100;
}

/* Voice button styling */
.voice-button-wrapper {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* Actions container */
.chat-input-actions {
    display: flex;
    align-items: center;
    justify-content: center; /* Center the button content */
    gap: 8px;
    flex-shrink: 0;
    height: 60px; /* Match the input field height for perfect alignment */
}

/* Recording state */
.recording .chat-input-optimized {
    pointer-events: none;
    opacity: 0.7;
}

/* Recording button styling - ensure circular red button */
.mud-icon-button.recording,
.chat-action-btn.recording {
    background-color: #f44336 !important;
    color: white !important;
    border-radius: 50% !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    max-width: 40px !important;
    max-height: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    aspect-ratio: 1 / 1 !important;
    animation: pulse-recording 1.5s infinite;
}

/* Pulse animation for recording */
@keyframes pulse-recording {
    0% {
        box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(244, 67, 54, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(244, 67, 54, 0);
    }
}

/* Mobile recording button */
@media (max-width: 768px) {
    .mud-icon-button.recording,
    .chat-action-btn.recording {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        max-width: 36px !important;
        max-height: 36px !important;
    }
}

/* Disabled state */
.chat-input-optimized:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Focus state - no border for clean look */
textarea.chat-input-optimized:focus {
    outline: none !important;
    border: none !important;
}

/* Placeholder styling */
.chat-input-optimized::placeholder {
    color: #9ca3af;
    opacity: 1;
}

/* Remove iOS default styling */
.chat-input-optimized::-webkit-input-placeholder {
    color: #9ca3af;
}

.chat-input-optimized::-moz-placeholder {
    color: #9ca3af;
    opacity: 1;
}

/* iOS-specific text selection fixes */
/* Prevent text selection on titles, headings, and UI elements */
h1, h2, h3, h4, h5, h6,
.welcome-greeting,
.mud-appbar,
.mud-button,
.mud-icon-button,
.mud-chip,
.mud-menu-item,
.app-logo-btn,
.user-dropdown,
.mud-nav-link,
.mud-typography,
.welcome-subtitle {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none; /* Prevents iOS callout menu */
}

/* Allow text selection only for message content and input fields */
.message-content,
.chat-input-optimized,
textarea,
input[type="text"],
input[type="email"],
input[type="password"] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* iOS Touch Responsiveness Fixes */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none; /* Disable callout on long press */
}

/* Fix iOS 300ms click delay */
a, button, [role="button"], .mud-button, .mud-icon-button,
.service-card, .mud-card, .chat-action-btn, .mud-menu-item {
    touch-action: manipulation !important; /* Eliminates 300ms delay */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* iOS-specific button fixes */
button, .mud-button, .mud-icon-button, [role="button"] {
    cursor: pointer !important;
    -webkit-appearance: none !important;
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
    /* Prevent hover state sticking */
    -webkit-touch-callout: none !important;
}

/* Fix iOS hover state issues */
@media (hover: none) and (pointer: coarse) {
    /* Mobile devices - disable problematic hover effects */
    .mud-button:hover, .mud-icon-button:hover, .service-card:hover,
    .chat-action-btn:hover, .mud-menu-item:hover {
        background-color: transparent !important;
        transform: none !important;
        box-shadow: none !important;
    }
}

/* Enhanced touch targets for iOS */
.mud-button, .mud-icon-button, .service-card {
    min-height: 44px !important; /* Apple's recommended minimum touch target */
    min-width: 44px !important;
}

/* Clickable areas should respond immediately on iOS */
.service-card, .mud-card {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1) !important;
    touch-action: manipulation !important;
}

/* Specifically target the welcome greeting that shows "HALLO, DUMMY AGENT" */
.welcome-container h1,
.welcome-container .welcome-greeting {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
    -webkit-tap-highlight-color: transparent !important;
}

/* iOS-specific fixes for external links (like "Zum Formular" button) */
.minimal-link {
    -webkit-touch-callout: default !important;
    -webkit-user-select: auto !important;
    touch-action: manipulation !important;
    cursor: pointer !important;
}

/* Force external links to work on iOS */
.minimal-link[target="_blank"] {
    -webkit-touch-callout: default !important;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1) !important;
}

/* iOS Safari fix for external links */
@supports (-webkit-touch-callout: none) {
    .minimal-link[target="_blank"] {
        display: inline-block !important;
        padding: 2px 4px !important;
        margin: -2px -4px !important;
        background: transparent !important;
        border: none !important;
        text-decoration: underline !important;
        color: var(--mud-palette-primary) !important;
        cursor: pointer !important;
        -webkit-appearance: none !important;
        -webkit-touch-callout: default !important;
    }

    .minimal-link[target="_blank"]:hover {
        background: rgba(var(--mud-palette-primary-rgb, 0, 61, 166), 0.1) !important;
    }
}