/**
 * Mobile Portal Styles
 * 
 * Mobile-first styles for the client portal to provide
 * a native app-like experience on mobile devices.
 * 
 * @package NCRHomeFinance
 * @subpackage ClientPortal
 */

/* ==========================================================================
   Base Mobile Styles
   ========================================================================== */

/* Prevent overscroll bounce on iOS */
body.portal-page {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

/* iOS safe areas */
.safe-area-top {
    padding-top: env(safe-area-inset-top, 0);
}

.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.safe-area-left {
    padding-left: env(safe-area-inset-left, 0);
}

.safe-area-right {
    padding-right: env(safe-area-inset-right, 0);
}

/* Hide scrollbars on mobile for cleaner look */
@media (max-width: 767px) {
    .portal-page ::-webkit-scrollbar {
        display: none;
    }
    
    .portal-page {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

/* ==========================================================================
   Touch Targets
   ========================================================================== */

/* Minimum touch target size of 44x44px for accessibility */
.touch-target {
    min-height: 44px;
    min-width: 44px;
}

/* Touch tap highlight removal */
.no-tap-highlight {
    -webkit-tap-highlight-color: transparent;
}

/* Press effect for cards and buttons */
.press-effect {
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
    -webkit-tap-highlight-color: transparent;
}

.press-effect:active {
    transform: scale(0.98);
}

/* Button press state */
.btn-press:active {
    transform: scale(0.95);
    opacity: 0.9;
}

/* ==========================================================================
   Cards & Containers
   ========================================================================== */

/* Mobile-optimized card */
.mobile-card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

/* Card with active/hover state */
.mobile-card-interactive {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-card-interactive:active {
    transform: scale(0.99);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

@media (min-width: 768px) {
    .mobile-card-interactive:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
}

/* ==========================================================================
   Property Cards - Mobile Optimized
   ========================================================================== */

.property-card-mobile {
    display: flex;
    flex-direction: row;
    background: white;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.property-card-mobile:active {
    transform: scale(0.99);
}

.property-card-mobile .property-image {
    width: 120px;
    height: 120px;
    flex-shrink: 0;
    object-fit: cover;
}

.property-card-mobile .property-content {
    flex: 1;
    padding: 0.75rem;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

@media (min-width: 640px) {
    .property-card-mobile {
        flex-direction: column;
    }
    
    .property-card-mobile .property-image {
        width: 100%;
        height: 180px;
    }
    
    .property-card-mobile .property-content {
        padding: 1rem;
    }
}

/* ==========================================================================
   Navigation & Tabs
   ========================================================================== */

/* Horizontal scrollable tabs for mobile */
.mobile-tabs {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px;
}

.mobile-tabs::-webkit-scrollbar {
    display: none;
}

.mobile-tab {
    flex-shrink: 0;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    background: #f3f4f6;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.mobile-tab.active {
    color: white;
    background: #2563eb;
}

.mobile-tab:active {
    transform: scale(0.95);
}

/* ==========================================================================
   Forms - Mobile Optimized
   ========================================================================== */

/* Mobile form inputs with proper touch targets */
.mobile-input {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 16px; /* Prevents iOS zoom on focus */
    border: 1px solid #d1d5db;
    border-radius: 0.75rem;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.mobile-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Select with custom arrow for mobile */
.mobile-select {
    width: 100%;
    padding: 0.875rem 2.5rem 0.875rem 1rem;
    font-size: 16px;
    border: 1px solid #d1d5db;
    border-radius: 0.75rem;
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.75rem center;
    background-size: 1.25rem;
    -webkit-appearance: none;
    appearance: none;
}

.mobile-select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Mobile button */
.mobile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 0.75rem;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
}

.mobile-btn:active {
    transform: scale(0.98);
}

.mobile-btn-primary {
    background: #2563eb;
    color: white;
}

.mobile-btn-primary:hover {
    background: #1d4ed8;
}

.mobile-btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.mobile-btn-secondary:hover {
    background: #e5e7eb;
}

/* ==========================================================================
   Modals & Overlays
   ========================================================================== */

/* Mobile-optimized modal */
.mobile-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 110;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    pointer-events: auto;
}

/* Ensure hidden modals don't block clicks */
.mobile-modal-overlay.hidden {
    display: none !important;
    pointer-events: none !important;
}

@media (min-width: 640px) {
    .mobile-modal-overlay {
        align-items: center;
        padding: 1rem;
    }
}

.mobile-modal {
    background: white;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 1.5rem 1.5rem 0 0;
    animation: slideUp 0.3s ease-out;
}

@media (min-width: 640px) {
    .mobile-modal {
        max-width: 28rem;
        border-radius: 1rem;
        animation: fadeIn 0.2s ease-out;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Modal drag handle for mobile */
.modal-drag-handle {
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 0.75rem auto 0;
}

@media (min-width: 640px) {
    .modal-drag-handle {
        display: none;
    }
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */

/* Toast positioned above bottom navigation */
.mobile-toast {
    position: fixed;
    bottom: 5rem; /* Above bottom nav */
    left: 1rem;
    right: 1rem;
    z-index: 80;
    transition: all 0.3s ease;
    pointer-events: none; /* Don't block clicks when invisible */
}

.mobile-toast.visible {
    pointer-events: auto;
}

@media (min-width: 768px) {
    .mobile-toast {
        left: auto;
        right: 1rem;
        bottom: 1.5rem;
        max-width: 24rem;
    }
}

.mobile-toast-content {
    background: #1f2937;
    color: white;
    padding: 1rem 1.25rem;
    border-radius: 0.75rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    pointer-events: auto; /* Allow clicks on toast content */
}

/* ==========================================================================
   Loading & Skeleton States
   ========================================================================== */

/* Skeleton loading animation */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Pulse loading for placeholders */
.skeleton-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ==========================================================================
   Empty States
   ========================================================================== */

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
}

.empty-state-icon {
    width: 4rem;
    height: 4rem;
    background: #f3f4f6;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #111827;
    margin-bottom: 0.5rem;
}

.empty-state-text {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 1.5rem;
}

/* ==========================================================================
   Step Indicators (Multi-step Forms)
   ========================================================================== */

/* Mobile-optimized step indicator */
.mobile-steps {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.5rem;
    margin-bottom: 1.5rem;
}

.mobile-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
}

.mobile-step-circle {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    background: #e5e7eb;
    color: #9ca3af;
    transition: all 0.3s ease;
}

.mobile-step.active .mobile-step-circle {
    background: #2563eb;
    color: white;
}

.mobile-step.completed .mobile-step-circle {
    background: #22c55e;
    color: white;
}

.mobile-step-label {
    font-size: 0.625rem;
    font-weight: 500;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.mobile-step.active .mobile-step-label {
    color: #2563eb;
}

.mobile-step.completed .mobile-step-label {
    color: #22c55e;
}

.mobile-step-line {
    flex: 1;
    height: 2px;
    background: #e5e7eb;
    margin: 0 0.25rem;
    margin-bottom: 1.125rem;
    transition: background 0.3s ease;
}

.mobile-step-line.active {
    background: #2563eb;
}

@media (min-width: 640px) {
    .mobile-step-circle {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 0.875rem;
    }
    
    .mobile-step-label {
        font-size: 0.6875rem;
    }
}

/* ==========================================================================
   Action Menus (Mobile Dropdown)
   ========================================================================== */

.action-sheet {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
}

.action-sheet.show {
    display: block;
}

.action-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s ease;
}

.action-sheet-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 1rem 1rem 0 0;
    padding: 0.5rem 0;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0));
    animation: slideUp 0.3s ease-out;
}

.action-sheet-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 1rem 1.5rem;
    font-size: 1rem;
    color: #374151;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
    min-height: 52px;
}

.action-sheet-item:active {
    background: #f3f4f6;
}

.action-sheet-item.danger {
    color: #dc2626;
}

.action-sheet-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 0.5rem 0;
}

.action-sheet-cancel {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 1rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: #2563eb;
    background: #f3f4f6;
    border: none;
    margin-top: 0.5rem;
    cursor: pointer;
    min-height: 52px;
}

.action-sheet-cancel:active {
    background: #e5e7eb;
}

/* ==========================================================================
   Pull to Refresh Indicator
   ========================================================================== */

.pull-refresh-indicator {
    position: fixed;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    transition: top 0.3s ease;
}

.pull-refresh-indicator.visible {
    top: calc(20px + env(safe-area-inset-top, 0));
}

.pull-refresh-spinner {
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   Status Badges
   ========================================================================== */

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
    text-transform: capitalize;
}

.status-active {
    background: #dcfce7;
    color: #166534;
}

.status-pending {
    background: #fef3c7;
    color: #92400e;
}

.status-inactive,
.status-deactivated {
    background: #f3f4f6;
    color: #6b7280;
}

.status-rejected {
    background: #fee2e2;
    color: #991b1b;
}

/* ==========================================================================
   Utilities
   ========================================================================== */

/* Line clamp utilities */
.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Truncate text */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Fade gradient for overflowing text */
.fade-overflow {
    position: relative;
}

.fade-overflow::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 2rem;
    background: linear-gradient(to right, transparent, white);
}

/* ==========================================================================
   PWA Standalone Mode
   ========================================================================== */

@media all and (display-mode: standalone) {
    /* Extra padding for status bar in PWA mode */
    .portal-header {
        padding-top: env(safe-area-inset-top, 20px);
    }
    
    /* Bottom nav safe area in PWA mode */
    .portal-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }
}
