/* ============================================
   MOBILE.css - All Mobile-Specific Styles, Bottom Sheet, Touch Targets
   ============================================
   Contains:
   - Touch-friendly targets
   - Mobile header improvements
   - Better form inputs for touch
   - PDF preview on mobile
   - Touch device optimizations
   - Mobile bottom sheet (fields panel)
   - Full-screen drawing mode (mobile)
   - Mobile layout adjustments
   - Mobile dark mode support
   ============================================ */

/* ============================================
   MOBILE OPTIMIZATIONS - Touch & Responsive
   ============================================ */

/* Touch-friendly targets */
@media (max-width: 768px) {
    /* Larger touch targets for buttons */
    .btn { 
        min-height: 44px; 
        min-width: 44px;
        padding: 0.75rem 1rem;
    }
    .btn-sm {
        min-height: 40px;
        padding: 0.6rem 0.9rem;
    }
    
    /* Better header for mobile */
    header {
        padding: 0.75rem 1rem;
    }
    .header-content {
        flex-wrap: wrap;
        gap: 0.75rem;
    }
    .logo-text {
        font-size: 1.25rem;
    }
    .logo span:first-child {
        font-size: 1.5rem;
    }
    
    /* Header right buttons - stack on very small screens */
    .header-right {
        width: 100%;
        justify-content: center;
        gap: 0.5rem;
    }
    
    /* Larger form inputs for touch */
    .add-field input {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Better PDF preview on mobile */
    .pdf-preview {
        min-height: 350px;
        max-height: 450px;
        padding: 0.5rem;
        -webkit-overflow-scrolling: touch;
    }
    .pdf-placeholder {
        height: 300px;
    }
    
    /* Touch-friendly PDF list items */
    .pdf-item {
        padding: 0.75rem;
        min-height: 48px;
    }
    .pdf-item-name {
        font-size: 0.9rem;
    }
    
    /* Touch-friendly field items */
    .field-item {
        padding: 0.75rem;
        min-height: 48px;
    }
    .field-item label {
        font-size: 1rem;
    }
    
    /* Larger radio buttons for touch */
    .field-item input[type="radio"] {
        width: 20px;
        height: 20px;
    }
    
    /* Better cards on mobile */
    .card {
        padding: 1rem;
    }
    .card-title {
        font-size: 1.1rem;
    }
    
    /* Intro section mobile improvements */
    .intro-title {
        font-size: 1.4rem;
    }
    .intro-subtitle {
        font-size: 1rem;
    }
    .step-card {
        padding: 1.25rem 0.75rem 1rem;
    }
    .step-icon {
        font-size: 2rem;
    }
    .step-title {
        font-size: 1rem;
    }
    .step-desc {
        font-size: 0.85rem;
    }
    
    /* Upload area */
    .upload-area {
        padding: 1.5rem 0.75rem;
    }
    .upload-icon {
        font-size: 2.5rem;
    }
    
    /* Container adjustments */
    .container {
        padding: 0.75rem;
    }
    
    /* Modals on mobile */
    .modal {
        padding: 1.25rem;
        margin: 0.5rem;
        max-height: 85vh;
        overflow-y: auto;
    }
    
    /* Dashboard mobile */
    .dashboard {
        padding: 1rem;
    }
    .dashboard-welcome h2 {
        font-size: 1.25rem;
    }
    .stat-card {
        padding: 0.75rem;
        min-width: 100%;
    }
    
    /* Offline indicator mobile */
    .offline-indicator {
        bottom: 0.5rem;
        left: 0.5rem;
        right: 0.5rem;
        font-size: 0.75rem;
    }
    
    /* Footer mobile */
    footer {
        padding: 1rem;
    }
    footer p {
        font-size: 0.7rem !important;
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .logo-text {
        font-size: 1.1rem;
    }
    .intro-title {
        font-size: 1.2rem;
    }
    .steps-grid {
        grid-template-columns: 1fr;
    }
    .header-right {
        gap: 0.35rem;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .upload-area:hover {
        background: transparent;
    }
    .pdf-item:hover {
        background: #f9fafb;
    }
    .field-item:hover {
        background: #f9fafb;
    }
    .btn:hover {
        transform: none;
    }
    .btn-success:enabled {
        animation: none;
    }
    
    /* Add active states for touch feedback */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    .pdf-item:active {
        background: #f5f3ff;
    }
    .field-item:active {
        background: #f5f3ff;
    }
    .upload-area:active {
        background: #f5f3ff;
    }
    
    /* Prevent text selection on interactive elements */
    .btn, .pdf-item, .field-item, .upload-area {
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Better touch scrolling */
    .pdf-preview, .pdf-list, .field-list, .extracted-list {
        -webkit-overflow-scrolling: touch;
    }
}

/* PDF highlight drawing on mobile */
@media (max-width: 768px) {
    .highlight-overlay {
        touch-action: none;
    }
    .highlight-box {
        min-width: 30px;
        min-height: 30px;
    }
    
    /* Info banner mobile */
    .info-banner {
        font-size: 0.75rem;
        padding: 0.4rem 0.75rem;
    }
    
    /* Extracted list mobile */
    .extracted-item {
        padding: 0.6rem;
        font-size: 0.8rem;
    }
    
    /* Batch progress mobile */
    #batchProgress {
        padding: 0.75rem;
    }
    #progressLabel {
        font-size: 0.85rem;
    }
}

/* Landscape mobile optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .pdf-preview {
        min-height: 250px;
        max-height: 350px;
    }
    .pdf-placeholder {
        height: 200px;
    }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .highlight-box {
        border-width: 2px;
    }
}

/* ============================================
   MOBILE BOTTOM SHEET - Fields Panel
   ============================================ */

/* Hide desktop-only elements on mobile, show on desktop */
@media (min-width: 769px) {
    .mobile-bottom-sheet {
        display: none !important;
    }
    .desktop-only {
        display: block;
    }
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
}

/* Mobile Bottom Sheet */
.mobile-bottom-sheet {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-height: 90vh;
    transition: transform 0.3s ease-out, max-height 0.3s ease-out;
    overflow: hidden;
}

@media (max-width: 768px) {
    .mobile-bottom-sheet {
        display: block;
    }
}

/* Bottom Sheet Handle */
.bottom-sheet-handle {
    padding: 12px 0 8px;
    display: flex;
    justify-content: center;
    cursor: grab;
    background: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

.bottom-sheet-handle:active {
    cursor: grabbing;
}

.handle-bar {
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
}

/* Collapsed State */
.bottom-sheet-collapsed {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 1rem 1rem;
    cursor: pointer;
}

.mobile-bottom-sheet.expanded .bottom-sheet-collapsed {
    display: none;
}

.swipe-indicator {
    font-size: 1.25rem;
    animation: bounce-up 1.5s ease-in-out infinite;
}

@keyframes bounce-up {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.field-count-text {
    font-size: 0.9rem;
    color: #6b7280;
    font-weight: 500;
}

/* Expanded Content */
.bottom-sheet-content {
    display: none;
    padding: 0 1rem 1rem;
    max-height: calc(90vh - 60px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-bottom-sheet.expanded .bottom-sheet-content {
    display: block;
}

.bottom-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    background: white;
    z-index: 5;
}

/* Mobile Field Input */
.mobile-field-input {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.mobile-field-input input {
    flex: 1;
    padding: 0.875rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 48px;
}

.mobile-field-input input:focus {
    outline: none;
    border-color: #7c3aed;
}

/* Mobile Field List */
.mobile-field-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
    max-height: 200px;
    overflow-y: auto;
}

.mobile-field-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    background: #f9fafb;
    border-radius: 12px;
    border: 2px solid transparent;
    min-height: 56px;
}

.mobile-field-item.selected {
    border-color: #7c3aed;
    background: #f5f3ff;
}

.mobile-field-name {
    font-size: 1rem;
    font-weight: 500;
    color: #374151;
    flex: 1;
}

.mobile-field-actions {
    display: flex;
    gap: 0.5rem;
}

.mobile-draw-btn {
    padding: 0.5rem 1rem;
    background: #7c3aed;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    min-height: 40px;
    min-width: 70px;
}

.mobile-draw-btn:active {
    background: #6d28d9;
}

.mobile-delete-btn {
    padding: 0.5rem;
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    min-height: 40px;
    min-width: 40px;
    font-size: 1.1rem;
}

.mobile-delete-btn:active {
    color: #ef4444;
}

/* Mobile Extracted Section */
.mobile-extracted-section {
    margin-bottom: 1rem;
}

.mobile-extracted-section h3 {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
}

.mobile-extracted-list {
    background: #f9fafb;
    border-radius: 12px;
    padding: 0.75rem;
    min-height: 60px;
    max-height: 120px;
    overflow-y: auto;
}

.mobile-extracted-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: #f5f3ff;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.mobile-extracted-item:last-child {
    margin-bottom: 0;
}

/* Mobile Actions */
.mobile-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.mobile-action-btn {
    flex: 1;
    min-width: calc(50% - 0.5rem);
    min-height: 44px;
}

/* Mobile Batch Section */
.mobile-batch-section {
    border-top: 1px solid #e5e7eb;
    padding-top: 1rem;
}

.mobile-process-btn,
.mobile-download-btn {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    min-height: 52px;
    margin-bottom: 0.5rem;
}

.mobile-download-btn {
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}

/* Mobile Progress */
.mobile-progress {
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
    border: 2px solid #c4b5fd;
    border-radius: 12px;
    padding: 1rem;
    margin-top: 0.75rem;
}

.mobile-progress-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: #6d28d9;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.mobile-progress-bar-container {
    background: white;
    border-radius: 8px;
    height: 14px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mobile-progress-bar {
    background: linear-gradient(90deg, #7c3aed 0%, #a78bfa 50%, #7c3aed 100%);
    background-size: 200% 100%;
    height: 100%;
    width: 0%;
    transition: width 0.3s;
    animation: shimmer 1.5s infinite;
}

/* Mobile Status */
.mobile-status {
    margin-top: 0.5rem;
}

/* ============================================
   ADDITIONAL MOBILE LAYOUT ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
    /* Main layout becomes single column */
    .main-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding-bottom: 80px; /* Space for bottom sheet */
    }
    
    /* Upload card adjustments */
    .upload-card {
        order: 1;
    }
    
    /* Preview card adjustments */
    .preview-card {
        order: 2;
    }
    
    /* Make PDF preview fit screen width */
    .pdf-preview {
        width: 100%;
        min-height: 300px;
        max-height: 50vh;
        overflow-x: auto;
        overflow-y: auto;
        padding: 0.5rem;
    }
    
    .pdf-page-container {
        max-width: 100%;
    }
    
    .pdf-page-container canvas {
        max-width: 100%;
        height: auto;
    }
    
    /* Better touch targets for all buttons */
    .btn {
        min-height: 48px;
        font-size: 1rem;
    }
    
    .btn-sm {
        min-height: 44px;
        font-size: 0.9rem;
    }
    
    /* Adjust info banner */
    .info-banner {
        flex-wrap: wrap;
        font-size: 0.85rem;
    }
    
    /* Container adjustments */
    .container {
        padding-bottom: 100px;
    }
}

/* Smooth transitions for mobile */
.mobile-bottom-sheet,
.bottom-sheet-content,
.mobile-field-item,
.mobile-draw-btn {
    transition: all 0.2s ease-out;
}

/* Dark mode support for mobile elements */
.dark-mode .mobile-bottom-sheet {
    background: var(--bg-secondary);
}

.dark-mode .bottom-sheet-handle .handle-bar {
    background: var(--border-light);
}

.dark-mode .field-count-text {
    color: var(--text-secondary);
}

.dark-mode .bottom-sheet-header {
    border-color: var(--border-color);
    background: var(--bg-secondary);
}

.dark-mode .mobile-field-input input {
    background: var(--bg-tertiary);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.dark-mode .mobile-field-item {
    background: var(--bg-tertiary);
}

.dark-mode .mobile-field-item.selected {
    background: var(--accent-light);
    border-color: #7c3aed;
}

.dark-mode .mobile-field-name {
    color: var(--text-primary);
}

.dark-mode .mobile-extracted-list {
    background: var(--bg-tertiary);
}

.dark-mode .mobile-extracted-item {
    background: var(--accent-light);
}

.dark-mode .mobile-batch-section {
    border-color: var(--border-color);
}

.dark-mode .drawing-mode-overlay {
    background: var(--bg-primary);
}

.dark-mode .drawing-mode-footer {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

.dark-mode .drawing-instructions {
    color: var(--text-secondary);
}

.dark-mode .drawing-mode-canvas-container {
    background: var(--bg-tertiary);
}
