/* ============================================
   MOBILE STYLES
   Responsive design for smartphones (< 768px)
   ============================================ */

/* Mobile visibility helpers (default hidden) */
.mobile-only {
    display: none !important;
}

.mobile-bottom-nav {
    display: none;
}

.mobile-contract-modal {
    display: none;
}

.mobile-progress-bar {
    display: none;
}

/* ========================================
   MOBILE-FIRST REDESIGN (< 768px)
   Complete UX overhaul for smartphones
   ======================================== */

@media (max-width: 768px) {
    
    /* Body */
    body {
        background: var(--background-muted);
        padding-bottom: 100px;
    }
    
    body.mobile-fullscreen {
        overflow: hidden;
    }
    
    .container {
        padding: 0;
        max-width: 100%;
    }
    
    /* Mobile Header - Compact */
    header {
        background: var(--bg-primary);
        padding: 16px 20px;
        margin-bottom: 0;
        position: sticky;
        top: 0;
        z-index: 100;
    }
    
    .logo-container {
        margin-bottom: 4px;
    }
    
    .logo-svg {
        height: 32px;
    }
    
    header p {
        font-size: 12px;
        opacity: 0.9;
    }
    
    /* Main Grid - Stack vertically */
    .main-grid {
        display: flex;
        flex-direction: column;
        gap: 0;
    }
    
    /* Mobile Step Indicator */
    .mobile-step-indicator {
        display: flex;
        justify-content: center;
        gap: 8px;
        padding: 16px 20px;
        background: white;
        border-bottom: 1px solid var(--border);
    }
    
    .mobile-step-dot {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background: var(--border);
        transition: all var(--transition-slow);
    }
    
    .mobile-step-dot.active {
        background: var(--accent);
        transform: scale(1.2);
    }
    
    .mobile-step-dot.completed {
        background: var(--accent);
    }
    
    /* PDF Section - Collapsible on mobile */
    .pdf-section {
        border-radius: 0;
        box-shadow: none;
        border-bottom: 1px solid var(--border);
    }
    
    .pdf-header {
        padding: 14px 16px;
        cursor: pointer;
        background: white;
    }
    
    .pdf-header::after {
        content: '';
        width: 20px;
        height: 20px;
        background-image: 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='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: center;
        transition: transform var(--transition-slow);
    }
    
    .pdf-section.expanded .pdf-header::after {
        transform: rotate(180deg);
    }
    
    .pdf-title {
        font-size: 14px;
    }
    
    .pdf-title-icon {
        width: 28px;
        height: 28px;
        border-radius: var(--radius-sm);
    }
    
    .pdf-title-icon svg {
        width: 14px;
        height: 14px;
    }
    
    .pdf-nav {
        display: none;
    }
    
    .pdf-section.expanded .pdf-nav {
        display: flex;
    }
    
    .pdf-viewer {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.4s ease;
    }
    
    .pdf-section.expanded .pdf-viewer {
        max-height: 60vh;
        overflow-y: auto;
    }
    
    /* Contract Document */
    .contract-document {
        padding: 16px;
        font-size: 11px;
    }
    
    .contract-header {
        padding: 12px;
    }
    
    .contract-logo-svg {
        height: 24px;
    }
    
    .contract-title {
        font-size: 14px;
    }
    
    /* Sidebar - Full width cards */
    .sidebar {
        width: 100%;
    }
    
    .card {
        border-radius: 0;
        box-shadow: none;
        border-bottom: 8px solid var(--border-light);
        padding: 20px 16px;
    }
    
    .card-title {
        font-size: 16px;
        margin-bottom: 16px;
    }
    
    .card-title .number {
        width: 26px;
        height: 26px;
        font-size: 13px;
    }
    
    /* Form inputs - Larger touch targets */
    .form-group {
        margin-bottom: 14px;
    }
    
    .form-group label {
        font-size: 13px;
        margin-bottom: 6px;
    }
    
    .form-group input {
        padding: 14px 12px;
        font-size: 16px; /* Prevents iOS zoom */
        border-radius: var(--radius-md);
    }
    
    /* Signature Section */
    .signature-info-box {
        padding: 12px;
        margin-bottom: 14px;
    }
    
    .signature-info-header {
        font-size: 13px;
    }
    
    .signature-info-box p {
        font-size: 12px;
    }
    
    .signature-methods-list li {
        font-size: 11px;
        padding: 5px 0;
    }
    
    /* Signature Method Selector - Horizontal scroll */
    .signature-method-selector.three-options {
        display: flex;
        flex-direction: row;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }
    
    .signature-method-selector.three-options .method-option {
        flex: 0 0 auto;
        min-width: 100px;
        padding: 12px 8px;
    }
    
    .signature-method-selector.three-options .method-icon {
        width: 36px;
        height: 36px;
    }
    
    .signature-method-selector.three-options .method-name {
        font-size: 12px;
    }
    
    .signature-method-selector.three-options .method-desc {
        font-size: 9px;
    }
    
    /* Signature Canvas - Taller on mobile */
    .signature-canvas-wrapper {
        border-radius: var(--radius-lg);
        min-height: 180px;
    }
    
    #signature-canvas {
        height: 180px !important;
    }
    
    .signature-placeholder {
        font-size: 13px;
    }
    
    .signature-placeholder svg {
        width: 20px;
        height: 20px;
    }
    
    .fullscreen-btn {
        width: 44px;
        height: 44px;
        top: 10px;
        right: 10px;
    }
    
    .signature-actions {
        gap: 8px;
        margin-top: 12px;
    }
    
    .btn-secondary {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    /* CMD Section */
    .cmd-info-box,
    .print-info-box {
        padding: 12px;
    }
    
    .cmd-info-box h4,
    .print-info-box h4 {
        font-size: 13px;
    }
    
    .cmd-info-box p,
    .print-info-box p {
        font-size: 12px;
    }
    
    .cmd-steps li,
    .print-steps li {
        font-size: 11px;
        padding: 5px 0 5px 22px;
    }
    
    .btn-cmd,
    .btn-print {
        padding: 14px 18px;
        font-size: 14px;
    }
    
    .send-reminder-box {
        padding: 12px;
        font-size: 12px;
    }
    
    /* Submit Card */
    #submit-card {
        padding-bottom: 24px;
    }
    
    .checkbox-group {
        gap: 10px;
    }
    
    .checkbox-group input[type="checkbox"] {
        width: 22px;
        height: 22px;
        min-width: 22px;
    }
    
    .checkbox-group label {
        font-size: 12px;
        line-height: 1.5;
    }
    
    .btn-primary {
        padding: 16px 20px;
        font-size: 15px;
        border-radius: var(--radius-lg);
    }
    
    /* Status Message */
    .status-message {
        font-size: 13px;
        padding: 12px;
    }
    
    /* Footer */
    footer {
        padding: 16px;
        font-size: 11px;
        margin-bottom: 80px;
    }
    
    /* Fullscreen Mode Enhancements for Mobile */
    .signature-canvas-wrapper.fullscreen {
        border-radius: 0;
    }
    
    .signature-canvas-wrapper.fullscreen .fullscreen-btn {
        top: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }
    
    .signature-canvas-wrapper.fullscreen .signature-placeholder {
        font-size: 20px;
    }
    
    .signature-canvas-wrapper.fullscreen .signature-placeholder svg {
        width: 40px;
        height: 40px;
    }
    
    .fullscreen-actions {
        bottom: 24px;
        gap: 12px;
    }
    
    .fullscreen-action-btn {
        padding: 16px 24px;
        font-size: 15px;
        border-radius: 14px;
    }
    
    .fullscreen-close-hint {
        bottom: 90px;
        font-size: 13px;
        padding: 10px 20px;
    }
    
    /* Mobile Bottom Navigation */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid var(--border);
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        z-index: 1000;
        gap: 12px;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
    }
    
    .mobile-nav-btn {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 14px 16px;
        border: none;
        border-radius: var(--radius-lg);
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        transition: all var(--transition-normal);
        font-family: inherit;
    }
    
    .mobile-nav-btn.secondary {
        background: var(--border-light);
        color: var(--text-secondary);
    }
    
    .mobile-nav-btn.secondary:hover {
        background: var(--border);
    }
    
    .mobile-nav-btn.primary {
        background: var(--accent);
        color: white;
    }
    
    .mobile-nav-btn.primary:hover {
        background: var(--accent-hover);
    }
    
    .mobile-nav-btn.primary:disabled {
        background: #cbd5e1;
        cursor: not-allowed;
    }
    
    /* Mobile Step Sections */
    .mobile-step {
        display: none;
    }
    
    .mobile-step.active {
        display: block;
    }
    
    /* Quick Contract Preview Button */
    .quick-contract-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        padding: 12px 16px;
        margin-bottom: 16px;
        background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
        border: 1px solid #7dd3fc;
        border-radius: var(--radius-md);
        color: #0369a1;
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        transition: all var(--transition-normal);
        font-family: inherit;
    }
    
    .quick-contract-btn:hover {
        background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
    }
    
    /* Mobile Contract Modal */
    .mobile-contract-modal {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: white;
        z-index: 2000;
        flex-direction: column;
    }
    
    .mobile-contract-modal.active {
        display: flex !important;
    }
    
    .mobile-modal-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px;
        background: var(--bg-primary);
        color: white;
        flex-shrink: 0;
    }
    
    .mobile-modal-header h3 {
        font-size: 16px;
        font-weight: 600;
        margin: 0;
    }
    
    .mobile-modal-close {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255,255,255,0.2);
        border: none;
        border-radius: var(--radius-md);
        color: white;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    
    .mobile-modal-close:active {
        background: rgba(255,255,255,0.3);
    }
    
    .mobile-modal-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
        background: var(--background-muted);
    }
    
    /* Contract document styling inside modal */
    .mobile-modal-body .contract-document {
        background: white;
        border-radius: var(--radius-lg);
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        padding: 16px;
    }
    
    .mobile-modal-body .contract-page {
        display: none;
    }
    
    .mobile-modal-body .contract-page.active {
        display: block !important;
    }
    
    .mobile-modal-body .contract-header {
        margin-bottom: 16px;
        padding-bottom: 12px;
        border-bottom: 1px solid var(--border);
    }
    
    .mobile-modal-body .contract-body {
        font-size: 13px;
        line-height: 1.6;
    }
    
    .mobile-modal-body .contract-body h3 {
        font-size: 14px;
        margin: 16px 0 8px 0;
        color: var(--text-primary);
    }
    
    .mobile-modal-body .contract-body p {
        margin-bottom: 10px;
    }
    
    .mobile-modal-nav {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        background: white;
        border-top: 1px solid var(--border);
        flex-shrink: 0;
    }
    
    .mobile-modal-nav button {
        width: 48px;
        height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--border-light);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: all var(--transition-normal);
    }
    
    .mobile-modal-nav button:active:not(:disabled) {
        background: var(--border);
        transform: scale(0.95);
    }
    
    .mobile-modal-nav button:disabled {
        opacity: 0.4;
        cursor: not-allowed;
    }
    
    .mobile-modal-nav span {
        font-size: 14px;
        font-weight: 500;
        color: var(--text-secondary);
    }
    
    /* Progress bar for mobile */
    .mobile-progress-bar {
        display: block;
        height: 4px;
        background: var(--border);
        position: relative;
    }
    
    .mobile-progress-fill {
        height: 100%;
        background: var(--accent);
        transition: width var(--transition-slow);
    }
    
    /* Floating Help Button */
    .mobile-help-btn {
        display: flex;
        position: fixed;
        bottom: 90px;
        right: 16px;
        width: 48px;
        height: 48px;
        align-items: center;
        justify-content: center;
        background: white;
        border: 1px solid var(--border);
        border-radius: 50%;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        color: var(--text-secondary);
        cursor: pointer;
        z-index: 999;
    }
    
    /* Show mobile elements, hide desktop elements */
    .mobile-only {
        display: block !important;
    }
    
    .desktop-only {
        display: none !important;
    }
    
    .quick-contract-btn {
        display: flex !important;
    }
    
    .mobile-bottom-nav {
        display: flex !important;
    }
}

/* Extra small devices - Further optimizations */
@media (max-width: 375px) {
    .form-group input {
        padding: 12px 10px;
    }
    
    .signature-method-selector.three-options .method-option {
        min-width: 90px;
        padding: 10px 6px;
    }
    
    .signature-method-selector.three-options .method-icon {
        width: 32px;
        height: 32px;
    }
    
    .mobile-nav-btn {
        padding: 12px 12px;
        font-size: 13px;
    }
    
    .fullscreen-action-btn {
        padding: 14px 20px;
        font-size: 14px;
    }
}
